Up Next Prev PrevTail Tail

### 7.11 MAP Operator

The MAP operator applies a uniform evaluation pattern to all members of a composite structure: a matrix, a list, or the arguments of an operator expression. The evaluation pattern can be a unary procedure, an operator, or an algebraic expression with one free variable.

It is used with the syntax:

MAP(FNC:function,OBJ:object)

Here OBJ is a list, a matrix or an operator expression. FNC can be one of the following:

1. the name of an operator with a single argument: the operator is evaluated once with each element of OBJ as its single argument;
2. an algebraic expression with exactly one free variable, i.e. a variable preceded by the tilde symbol. The expression is evaluated for each element of OBJ, with the element substituted for the free variable;
3. a replacement rule of the form var => rep where var is a variable (a kernel without a subscript) and rep is an expression that contains var. The replacement expression rep is evaluated for each element of OBJ with the element substituted for var. The variable var may be optionally preceded by a tilde.

The rule form for FNC is needed when more than one free variable occurs.

Examples:

map(abs,{1,-2,a,-a})  ->  {1,2,ABS(A),ABS(A)}
map(int(~w,x), mat((x^2,x^5),(x^4,x^5))) ->

[  3     6 ]
[ x     x  ]
[----  ----]
[ 3     6  ]
[          ]
[  5     6 ]
[ x     x  ]
[----  ----]
[ 5     6  ]

map(~w*6, x^2/3 = y^3/2 -1) -> 2*X^2=3*(Y^3-2)

You can use MAP in nested expressions. However, you cannot apply MAP to a non-composite object, e.g. an identifier or a number.

 Up Next Prev PrevTail Front