An array is only useful if you can read from it. Today you parse and evaluate the index operator arr[i], treating the opening bracket as an infix operator - and decide what an out-of-range index produces.
Parse and evaluate array indexing, returning null for an out-of-range index.
Reading an element uses the index operator arr[i], which - like a call - is
really an infix use of a bracket: the expression on the left is the array, and
the expression inside the brackets is the position. Register [ as an infix parse
function at INDEX precedence, the tightest of all so arr[0] binds before any
surrounding operator.
The design decision is out-of-bounds behavior: rather than crash or error, an
index past the end - or a negative one - evaluates to null. That keeps indexing
total (it always produces a value) and composes nicely with the truthiness rules,
so callers can test the result. Evaluate the array and the index, bounds-check,
and return the element or null.
type IndexExpression struct { Left Expression; Index Expression }const ( /* ...levels... */ INDEX ) // even tighter than CALLprecedences["["] = INDEX// register '[' as an INFIX parse fn too; eval:// evaluate Left (array) and Index (integer); bounds-check before reading