The documentation uses a notation to show how the stack is modified when a
calculator operation is evaluated. This stack notation is similar to the
notation found in documentation for the Forth programming language. The
following is an example of the notation to indicate that an operation consumes
two Int
values from the stack and pushes one Int
value back to the
stack:
( Int Int -- Int )
Stack notation is enclosed by parenthesis ()
, items consumed from the
stack are to the left of --
, and items produced to the stack are on the
right of --
. The top of the stack is the right-most element.
An operation that consumes no values from the stack is notated as:
( -- Int )
An operation that produces no values to the stack is notated as:
( Int -- )
An operation that does not modify the stack is shown by:
( -- )
Parameters can be named by placing a name and a :
before the type:
( x:BigInt y:BigInt -- BigInt )
If an operation returns more than one value, the values may be also be named:
( x1:Float y1:Float -- x2:Float y2:Float )
When a there is a name that is the same on both sides of the --
, that
indicates that the operation does not change the value. In the following
example, the y value is changed but the x value is not:
( x:Float y1:Float -- x:Float y2:Float )
A suffix of *
is used when the parameter consumes the remaining elements of
the stack. if any. For example, the stack notation for the sum
operation for
Dec
values is:
( Dec* -- Dec )
When a *
suffix appears on a return type, that value can be found any number
of times. For example, the stack notation for the repeat
operation is:
( expr:Any n:Int -- Any* )