4.2. Naming Variables in the User Dictionary

You can store any value type as an element in the user dictionary using the 'def' command. In the example below we will rewrite the '1+2' example from before using named variables.

Example 4-4. 1+2 using named variables

/a 1 def
/b 2 def
a b add print

The value 1.0 is assigned to 'a' in the user dictionary using the def command, which takes a string and a value as operands. The value 2.0 to 'b'. Then the values are recalled using 'a' and 'b' as literals. Because 'a' is used as a literal it is reference in the user dictionary when it is executed and the value found in the user (or system) dictionary is then executed. In this case the value 1.0 is executed, which, because it is a simple value, is pushed onto the operand stack.