Example: In the following program excerpt, the defining procedure for local variables d, e, and f calls a program that you previously created and stored in global variable P1.

Program:

Comments:

 

 

«

 

:

 

→ a b c

 

«

 

a b + c +

 

→ d e f

Defines local variables d, e, f.

'P1+a/(d*e+f)'

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

 

in this procedure. The defining procedure

 

executes the program stored in variable P1.

a c / -

 

»

 

:

 

»

 

 

 

The six local variables are not available in program P1 because they didn’t exist when you created P1. The objects stored in the local variables are available to program P1 only if you put those objects on the stack for P1 to use or store those objects in global variables.

Conversely, program P1 can create its own local variable structure (with any names, such as a, c, and f, for example) without conflicting with the local variables of the same name in the procedure that calls P1. It is possible to create a special type of local variable that can be used in other programs or subroutines. This type of local variable is called a compiled local variable.

Compiled Local Variables

Global variables use up memory, and local variables can’t be used outside of the program they were created in. Compiled local variables bridge the gap between these two variable types. To programs, compiled local variables look like global variables, but to the calculator they act like local variables. This means you can create a compiled local variable in a local variable structure, use it in any other program that is called within that structure, and when the program finishes, the variable is gone.

Compiled local variables have a special naming convention: they must begin with a . For example,

«

←y

'IFTE(←y<0,BELOW,ABOVE)'

»

The variable ←y is a compiled local variable that can be used in the two programs BELOW and ABOVE.

Creating User-Defined Functions as Programs

The defining procedure for a local variable structure can be either an algebraic or program object.

A program that consists solely of a local variable structure whose defining procedure is an algebraic expression is a user-defined function.

1-10 RPL Programming