Getter Expressions
A getter expressions consists of the @ character followed by an
object property name or an array index. It
retrieves the value of the property or the element at the index for an input
object or array. The input type must guarantee the existence of the
property/index, otherwise a type error is raised. If the input type cannot
guarantee the existence of the property/index, use the get funcer for
objects or for arrays.
| Program | Type | Value | Error |
|---|---|---|---|
{a: 1, b: 2} @a | Num | 1 | |
{a: 1, b: 2} @b | Num | 2 | |
{a: 1, b: 2} @c | Type error | ||
{0: "a"} @0 | Str | "a" | |
["a", "b", "c"] @0 | Str | "a" | |
["a", "b", "c"] @1 | Str | "b" | |
["a", "b", "c"] @2 | Str | "c" | |
["a", "b", "c"] @3 | Type error | ||
["a", "b", "c"] @-1 | Type error | ||
["a", "b", "c"] @1.5 | Type error | ||
"abc" @1 | Type error | ||
24 @1 | Type error | ||
for Any def f Arr<Any...> as [] ok f @1 | Type error |