Subscript Operator Overloading
Overloading the [] operator allows custom types to support array-like index access syntax. The subscript operator has two forms: the getter form arr[i] and the setter form arr[i] = value, distinguished by whether a named parameter value! exists.
The code on the right defines a Grid class representing a 2D table. The getter form operator func [](row, col) returns the cell value; the setter form operator func [](row, col, value!) takes a special named parameter value! (note the exclamation mark), and the return type must be Unit.
The subscript operator supports multiple index parameters, not limited to single-dimensional arrays. When calling, you don't need to write the named parameter form grid[row, col, value: v], just use grid[row, col] = v directly.
value in the setter form is a special marker; when calling, you don't need to pass a named parameter, just use the arr[i] = value syntax directly.Try adding boundary checking to print an error message instead of crashing when the index is out of bounds.