This example changes every call to to a call to .
Shift all symbols by a constant of .
Expand all products in an expression.
Using evalindets, you can avoid expanding things you might not want expanded.
Optional arguments may be passed to the transformer.
The following example demonstrates the use of evalindets[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:
>
|
evalindets(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:
>
|
evalindets['nocache'](expr,symbol,proc(s) global count; count:=count+1; cat(s,count) end);
|
The following example demonstrates the use of evalindets[N]
The evalindets[N] calling sequence is used when you want to pass additional arguments to the transformer function before the subexpression to be transformed:
This calls op(1,x) for each subexpression, of type specfunc(f).
Without the [N] option, the alternative would be to introduce a procedure that takes a single argument , and returns op(1,x):
This is less efficient because of the extra level of procedure calling. The evalindets command calls your procedure which calls op, instead of just calling op directly.
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 evalindets as the transformer.
This works because the outer call to evalindets 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.