Pseudo Operators

Home, Up: Operators and Constants

 

This page (unlike the next one) is intended for advanced users.

WHISK and DONE are called "pseudo operators" because, like operators, they remove arguments to their left, but do not perform any calculations.

 

On this page:

Pseudo Operator WHISK, Pseudo Operator DONE.

 

Pseudo Operator WHISK

WHISK removes ("whisks away") the two arguments to its left and stores them under the names A and B, which can then be used in the calculation line.

This is useful when a calculation involves the same values more than once (see also the pseudo constant DUP, page Pseudo Constants later in this chapter), or to create user-defined 2-argument operators (see page User-Defined Operators in chapter "Insert Files and User-Defined Elements").

 

A simple example, just to show how WHISK works -- calculating the length of the hypotenuse of a rectangular triangle:

? 3 4 WHISK A SQ B SQ + SQRT

= 5

A takes the value of 3, B the value of 4. A gets squared, then B gets squared, then the results are added, and the square root is drawn.

You'd get the same result with 3 SQ 4 SQ + SQRT, but WHISK lets you write the two arguments 3 and 4 next to each other, without an operator in between. We will use this example when we discuss user-defined operators.

 

You can use WHISK several times in one calculation line, each time the previous values of A and B will be overwritten.

A and B can only be used following WHISK within the same calculation line.

The values of A and B are not preserved after the line has been processed -- this is deliberate.

WHISK deliberately does not auto-include $ at the beginning of the calculation line!

 

In some cases you may want to "whisk away" only a single value -- you can do this by putting a dummy value (for instance, 0) before WHISK, and then only use A as often in your calculation line where you need it.

WHISK offers a more flexible way of using the same value several times than the pseudo constant DUP, but DUP has its uses, too.

Where WHISK doesn't solve your problem you have to look at variables, scripts and loops.

 

Pseudo Operator DONE

DONE preserves the value immediately to its left, and deletes all prior values from the calculation.

Example:

? 3 4 5 7 + DONE

= 12

The + operator adds 5 and 7 and replaces them with the result 12, then DONE keeps this value but deletes the remaining numbers to the left. Without DONE the calculation would have produced an error due to the remaining surplus arguments.

While it may seem to make little sense to enter numbers only to ignore and delete them, there are actually cases where this feature may be helpful. Admittedly, though, these are rare and DONE is something that you'll probably never need.

 

Home, Up: Operators and Constants, Prev: n-Argument Operators, Next: Constants