indexing operator - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


`?[]`

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

tbltablethree=3,four=4,one=1,two=2

(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

tablesix=6,five=5,three=3,four=4,one=1,two=2

(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