This example changes every call to to a call to .
>
|
|
| (1) |
>
|
|
>
|
|
| (3) |
>
|
|
| (4) |
Shift all symbols by a constant of .
>
|
|
| (5) |
Expand all products in an expression.
>
|
|
| (6) |
>
|
|
| (8) |
Using subsindets, you can avoid expanding things you might not want expanded.
>
|
|
Optional arguments may be passed to the transformer.
>
|
|
| (10) |
>
|
|
| (11) |
>
|
|
| (12) |
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
| (15) |
The following example demonstrates the use of subsindets[nocache]
In this first case, without nocache, the transformer function will be called at least once, and most likely only once, though this is not guaranteed, for each matching subexpression:
>
|
subsindets(expr,symbol,proc(s) global count; count:=count+1; cat(s,count) end);
|
In this next case, with the nocache option, the transformer function is guaranteed to be called once for every instance of each matching subexpression:
>
|
subsindets['nocache'](expr,symbol,proc(s) global count; count:=count+1; cat(s,count) end);
|
This example illustrates the remark above about the order in which subexpressions at various levels of nesting depth are processed. In it, we replace each integer in the expression that occurs inside a function call with a name that indicates the name of the closest enclosing function. This is done by using a second call to subsindets as the transformer.
| (18) |
>
|
|
| (19) |
This works because the outer call to subsindets processes h(6) (turning it into h(`6 in f`)) before it processes the calls to g or f; so when the transformer processes those calls, the integer 6 doesn't occur anymore.