For example, the user function COT (from chapter 5) was written:
Here the local-variable structure stores one argument in a local vari-
able }:: (satisfying the first requirement) and evaluates the expression
::<::0 : : 0 '
(satisfying the second requirement). The user func-
tion O-C (from chapter 14) included a program rather than an
expression but, since the program returned exactly one result, O-C
also satisfied the second requirement.
These requirements apply only to user functions. More generally, local
variables are used as a substitute for stack manipulations. The follow-
ing example returns the sum and difference of two numbers. Since it
returns two results, it can't be a user function.
+ x y -
For more examples, see the programs in chapter 28. They use local-
variable structures more often to avoid stack manipulations than to
create user functions.
Conditional structures enable a program to test a specified condition
and make a decision based on the result of the test. This section first
gives an example of a conditional structure.
uses that example to
discuss program structures in general, and then it describes other
types of conditional structures.
Suppose you're writing a program that uses the variable x, and you
want to calculate (sin
A problem arises because the quotient is
O. The following example returns (sin
0, or returns 1 if
IF X 0
THEN X SIN X / ELSE 1 END
26: Program Structures