Home · A · B · C · D · E · F · G · H · I · J · K · L · M · N · O · P · Q · R · S · T · U · V · W · X · Y · Z · Numbers & Symbols

The Compleat User RPL Encyclopedia


(“Right Arrow”)

Syntax #1:  'var(s)' 'expr'   
  Syntax #2:  'var(s)' « routine »
Keyboard Access (all models): RS-0 (zero)

Create Local Variables command. Also called “arrow”, “bind”, “create”, “assign”, and “to”.

Can only be used inside programs in one of the two syntaxes shown above. 'var(s)' is one or more variable names separated by spaces, 'expr' is any algebraic expression, and « routine » is anything between two program delimiters. In each case,  creates the local vars indicated, stores whatever is on the stack into them, and keeps them in existence only for the duration of 'expr' or « routine » , and then automatically purges them. HP calls 'expr' or « routine » the “defining procedure” of the local variables. The rest of the world calls them the “scope” of the local variables.

Example:


    8 7 'b'

because the « a » returns the 8 that was stored into 'a' then deletes the local variables 'a' and 'b' which were created only for the duration of that routine; then the following a (a global variable, not a local variable!) recalls the 7 that was stored into it at the beginning; and the 'b' (global variable!) which has nothing stored in it gets left on the stack since it is undefined.

Notice that inside the defining procedure « a », there exist two variables both called 'a', one local, and one global. The local one “wins”; there is no way (with ordinary User RPL) to access a global variable when a local one of the same name exists, not even by specifying its path, as this example illustrates:
 
    153 (the local value), not 7 (the global value).
This is because the 'a' in the defining procedure is compiled as a local variable, which does not refer to the global 'a'.

BYTES: 2.5