Pike v8.0 release 1738

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 as predef::`^(a,"b") where "b" is the symbol b 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 with index 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 in arg.

int

The bignum function named index will be looked up in arg.

array

An array of all elements in arg arrow indexed with index will be returned.

mapping

If index exists in arg the corresponding value will be returned. Otherwise UNDEFINED will be returned.

multiset

If index exists in arg, 1 will be returned. Otherwise UNDEFINED will be returned.

program

The non-protected (ie public) constant symbol index will be looked up in arg.

Note

In an expression a->b, the symbol b 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

`[](), lfun::`->(), ::`->(), `->=