The following procedure has its arguments fully evaluated at the top level, but evaluated to only one level when called within the (anonymous) procedure shown.
>
|
p := proc( x ) print( x ); end proc;
|
| (1) |
>
|
proc()
local a, b;
a := b;
b := 2;
p(a);
end proc();
|
Modifying the formal parameter of changes it so that it has special evaluation rules.
>
|
p := proc( x::uneval ) print( x ); end proc;
|
| (6) |
>
|
proc()
local a, b;
a := b;
b := 2;
p(a);
end proc();
|
The procedure evalf has special evaluation rules because it ensures that its second argument (if provided) is evaluated before its first argument.
>
|
evalf( proc() print( FIRST ); Pi end(), proc() print( SECOND ); 15 end() );
|
The procedure assigned uses a non-standard evaluator (evaln) when it evaluates its argument.
You can control the order of argument evaluation by suppressing it entirely and making the evaluations explicit in the desired order.
>
|
p := proc( a::uneval, b::uneval )
local ea, eb;
eb := eval( b ); # evaluate second
ea := eval( a ); # evaluate first
[ ea, eb ]
end proc:
|
>
|
p( proc() print(FIRST); 2 end(), proc() print(SECOND); 3 end() );
|