Page 21-35
« “Enter a: “ {“:a: “ {2 0} V } INPUT OBJ→→ a « ‘2*a^2+3‘
EVAL ”F” →TAG a SWAP»»
(Recall that the function SWAP is available by using „°@)STACK @SWAP@).
Store the program back into FUNCa by using „ @FUNCa. Next, run the
program by pressing @FUNCa . Enter a value of 2 when prompted, and press
`. The result is now two tagged numbers a:2. in stack level 2, and F:11.
in stack level 1.
To see the operation of the function FUNCa, step by step, you could use the
DBUG function as follows:
³ @FUNCa ` Copies program name to stack level 1
„°LL @)@RUN@ @@DBG@ Starts debugger
@SST
↓@ Step-by-step debugging, result: “Enter a:”
@SST
↓@ Result: {“ a:” {2 0} V}
@SST
↓@ Result: user is prompted to enter value of a
2` Enter a value of 2 for a. Result: “:a:2”
@SST
↓@ Result: a:2
@SST
↓@ Result: empty stack, executing →a
@SST
↓@ Result: empty stack, entering subprogram «
@SST↓@ Result: ‘2*a^2+3’
@SST
↓@ Result: empty stack, calculating
@SST
↓@ Result: 11.,
@SST
↓@ Result: “F”
@SST
↓@ Result: F: 11.
@SST
↓@ Result: a:2.
@SST
↓@ Result: swap levels 1 and 2
@SST
↓@ leaving subprogram »
@SST
↓@ leaving main program »
Note: Because we use an input string to get the input data value, the local
variable a actually stores a tagged value ( :a:2, in the example above).
Therefore, we do not need to tag it in the output. All what we need to do is
place an a before the SWAP function in the subprogram above, and the
tagged input is placed in the stack. It should be pointed out that, in
performing the calculation of the function, the tag of the tagged input a is
dropped automatically, and only its numerical value is used in the calculation.