next up previous contents
Next: Swapping items using Up: CHAPTER.3: PROCEDURES AND Previous: Clearing items from

Removing unwanted items from the stack

The procedure erase simply removes one item from the stack, so in:

        erase(2 + 2) =>
the expression in the parentheses will be evaluated but no result will be printed. Erase is sometimes useful if you want only one of the results of a procedure which produces two results. E.g. the operation `//' performs integer division putting the remainder and the quotient on the stack:

        23 // 6 =>
        ** 5 3
If you wanted to assign only the remainder to X, you could do:

        erase(23 // 6) -> x;
        x =>
        ** 5
or, using an extra "assignment to nothing" instead of erase:

        (23 // 6) -> -> x;
        x =>
        ** 5
(Actually the infix operation REM does the same:

        23 rem 6 -> x;
        x =>
        ** 5
)

To assign the divisor first assign the top of the stack, then erase the second result:

    erase(23 // 6 -> x);
    x =>
    ** 3
or, using assignment to nothing

    23 // 6 -> x ->;
    x =>
    ** 3
(This can be done instead using the infix operator `div':

    23 div 6 =>
    ** 3
)



Aaron Sloman
Fri Jan 2 03:17:44 GMT 1998