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;
Here is what happens when qproc(y) is executed:
First the argument y is evaluated, and the formal parameter x is replaced by the result (which is ) throughout the body of the procedure.
Now b is assigned the value (note that a has no value other than itself yet).
Then , which is the replacement of x+1 , is assigned to a .
Finally, the local variable b is evaluated one level (obtaining ), but the local variable a is not further evaluated there. The value this local variable had is not lost (even though the procedure that owned it has terminated): we can have it evaluated by using %.
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;
See also: Assignments do not commute , eval , Last name evaluation
Maple Advisor Database, R. Israel 1997