Extracted from Pike v7.6 release 61 at 2005-12-30.
pike.ida.liu.se
[Top]

Method `[]()


Method `[]

mixed `[](object arg, mixed index)
mixed `[](object arg, string index)
mixed `[](int arg, string index)
mixed `[](array arg, int index)
mixed `[](array arg, mixed index)
mixed `[](mapping arg, mixed index)
int(0..1) `[](multiset arg, mixed index)
int `[](string arg, int index)
mixed `[](program arg, string index)
mixed `[](object arg, mixed start, mixed end)
string `[](string arg, int start, int end)
array `[](array arg, int start, int end)

Description

Index/subrange.

Every non-lvalue expression with the [] operator becomes a call to this function, i.e. a[i] is the same as predef::`[](a,i) and a[i..j] is the same as predef::`[](a,i,j). If the lower limit i is left out, 0 is passed to the function. If the upper limit j is left out, Int.NATIVE_MAX is passed to the function, but that might be changed to an even larger number in the future.

Returns

If arg is an object that implements lfun::`[]() , that function will be called with the rest of the arguments.

If there are 2 arguments the result will be as follows:

arg can have any of the following types:
object

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

int

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

array

If index is an int, index number index of arg will be returned. Otherwise an array of all elements in arg 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.

string

The character (int) at index index in arg will be returned.

program

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


Otherwise if there are 3 arguments the result will be as follows:

arg can have any of the following types:
string

A string with the characters between start and end (inclusive) in arg will be returned.

array

An array with the elements between start and end (inclusive) in arg will be returned.


Note

An 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::`[]() , `[]=