Advice: One level evaluation for local variables

Inside a procedure, Maple uses one-level evaluation on local variables, instead of the full evaluation which is used on global variables. In most cases this is all that is needed, and in some cases it results in substantially improved efficiency.

> qproc:= proc(x) local a,b;
b:= a+1;
a:= x+1;
b;
end:
qproc(y);

a+1

Here is what happens when qproc(y) is executed:

> %;

y+2

Under most circumstances we want the results our procedures return to be fully evaluated, and not to contain local variables. Careful consideration of the order in which assignments are made can usually remedy the situation. If necessary, you can fully evaluate an expression using eval . Thus the procedure above could be rewritten:

> qproc2:= proc(x) local a,b;
b:= a+1;
a:= x+1;
eval(b);
end:
qproc2(y);

y+2

See also: Assignments do not commute , eval , Last name evaluation

Maple Advisor Database, R. Israel 1997