`?[]` - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Data Types : Tables, lists, and sets : indexing_operator

`?[]`

the indexing operator

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

`?[]`(x, l)

`?[]`(x, l, m)

Parameters

x

-

expression to be indexed

l

-

list of indices

m

-

list of values to assign

Description

• 

The indexing operator, `?[]`, provides a way to encode the process of indexing an expression in a function call.

• 

The first calling sequence evaluates to the expression x, indexed by the entries of the list l. For example, `?[]`(tbl, [a, b]) evaluates to tbl[a, b].

• 

Evaluating the second calling sequence assigns the expression sequence contained in the list m to the entry that the first calling sequence evaluates to. For example, evaluating `?[]`(tbl, [a, b], [c, d]) is the same as running the statement tbl[a, b] := c, d;.

• 

The help page object,operators discusses some of the uses and consequences of overriding the indexing operator in an object. Briefly, it allows the object author to define the behavior when an object is indexed.

Examples

tbltableone=1,two=2,three=3,four=4

tbltableone=1,two=2,three=3,four=4

(1)

To obtain a table entry, you can index the table directly, or use the indexing operator.

tblone=`?[]`tbl,one

1=1

(2)

To assign a table entry, you can use indexing syntax, or use the indexing operator.

tblfive5

tblfive5

(3)

`?[]`tbl,six,6

tblsix

(4)

evaltbl

tableone=1,two=2,five=5,six=6,three=3,four=4

(5)

You can use the indexing operator to obtain a list of entries in a table, using the map2 command.

idstwo,six,three,two

idstwo,six,three,two

(6)

map2`?[]`,tbl,ids

2,6,3,2

(7)

The indexing operator works with all expressions that can be indexed, not just tables. The following map statement indexes a list, a Vector, and a variable with the number 2. This returns the second entries of the list and the Vector, and the unevaluated indexed variable.

lst4,5,6

lst4,5,6

(8)

vec7,8,9

vec789

(9)

map`?[]`,lst,vec,var,2

5,8,var2

(10)

See Also

selection