Evaluating Local Names

Local names are evaluated differently from global names. When a global name is evaluated, the object stored in the corresponding variable is itself evaluated. (You’ve seen how programs stored in global variables are automatically evaluated when the name is evaluated.)

When a local name is evaluated, the object stored in the corresponding variable is returned to the stack but is not evaluated. When a local variable contains a number, the effect is identical to evaluation of a global name, since putting a number on the stack is equivalent to evaluating it. However, if a local variable contains a program, algebraic expression, or global variable name — and if you want it evaluated — the program should execute EVAL after the object is put on the stack.

Defining the Scope of Local Variables

Local variables exist only inside the defining procedure.

Example: The following program excerpt illustrates the availability of local variables in nested defining procedures (procedures within procedures). Because local variables a, b, and c already exist when the defining procedure for local variables d, e, and f is executed, they’re available for use in that procedure.

Program:

Comments:

 

 

«

 

.

 

.

 

.

No local variables are available.

 

→ a b c

Defines local variables a, b, c.

«

Local variables a, b, c are available

a b + c +

in this procedure.

→ d e f

Defines local variables d, e, f.

'a/(d*e+f)'

Local variables a, b, c and d, e, f are

 

available in this procedure.

a c / -

Only local variables a, b, c are

»

available.

.

No local variables are available.

.

 

.

 

»

 

 

 

RPL Programming 1-9