11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.1 Nested Procedures • 5procedure. What happens if you define this variable, v, as local to theinvocation of the procedure within map?> nest2 := proc(x::list)> local v;> v := x[1];> map( proc(y) local v; y/v; end, x );> end proc:> nest2(lst);[ 8 v , 4 v , 2 v , 16v ]The nest2 procedure produces different results. When the variablesare declared in the inner procedure, the proper values from the enclosingprocedure are not used. Either a variable is local to a procedure andcertain procedures that are completely within it, or it is global to theentire Maple session.Rule Maple determines whether a variable is local or global, from theinside procedure to the outside procedure. The name of the variable issearched for among:1. Parameters of the inner procedure2. Local declarations and global declarations of the inner procedure3. Parameters of the outside procedure4. Local and global declarations of the outside procedure5. Implicitly declared local variables of any surrounding procedure(s)If found, that specifies the binding of the variable.If, using the above rule, Maple cannot determine whether a variableis global or local, the following default decisions are made.• If a variable appears on the left side of an explicit assignment or asthe controlling variable of a for loop, Maple regards the variable aslocal.• Otherwise, Maple regards the variable as global to the whole session.In particular, Maple assumes by default that the variables you pass asarguments to other procedures, which may set their values, are global.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!