Method `->()
- Method `->
mixed
`->(object
arg
,string
index
)
mixed
`->(int
arg
,string
index
)
mixed
`->(array
arg
,string
index
)
mixed
`->(mapping
arg
,string
index
)
bool
`->(multiset
arg
,string
index
)
mixed
`->(program
arg
,string
index
)- Description
Arrow indexing.
Every non-lvalue expression with the
->
operator becomes a call to this function.a->b
is the same aspredef::`^(a,"b")
where"b"
is the symbolb
in string form.This function behaves like `[], except that the index is passed literally as a string instead of being evaluated.
- Returns
If
arg
is an object that implements lfun::`->(), that function will be called withindex
as the single argument.Otherwise the result will be as follows:
arg
can have any of the following types:object
The non-protected (ie public) symbol named
index
will be looked up inarg
.int
The bignum function named
index
will be looked up inarg
.array
An array of all elements in
arg
arrow indexed withindex
will be returned.mapping
If
index
exists inarg
the corresponding value will be returned. OtherwiseUNDEFINED
will be returned.multiset
If
index
exists inarg
,1
will be returned. OtherwiseUNDEFINED
will be returned.program
The non-protected (ie public) constant symbol
index
will be looked up inarg
.- Note
In an expression
a->b
, the symbolb
can be any token that matches the identifier syntax - keywords are disregarded in that context.- Note
An arrow indexing expression in an lvalue context, i.e. where the index is being assigned a new value, uses `->= instead of this function.
- See also