Program Menu
IMPORTANT NOTE: before getting started on programming the calculator, please have a look at the Important Programming Notes section.
The functions contained in the programming menu are generally best suited for writing simple functional programs. However, they are also sometimes useful in "regular" calculations. In fact, there is no clear dividing line in the calculator between what constitutes a functional program and a regular calculation, other than the use of undefined names (or variables).
Important Note: All examples listed in this page may be copied and pasted directly into the calculator register if you wish to see the example in action. They may be copied in their entirety, or one line at a time, or however you wish to do it. (If pasting a block of commands, select a stack entry, not the register.)
Fref (Function reference)
Insertion of a function reference results in a function call being inserted with a given set of arguments, with the function itself to be defined later. The stack inputs for Fref are:
argument(s) to function, name of function
If the function takes more than one argument, the multiple arguments must be in a list. The use model for Fref will make a bit more sense if we look at some examples.
Fref defined later in stack
One use of Fref would be to express a function call which is to be defined later. This is not the most common use case, but it makes a simple example. For instance, entering the following:
12 MyFunction Fref
Will result in the stack looking like this:
The result indicates dependency on the definition of the function (which is still undefined). Now, if the next entry on the stack is the following:
x 3 + MyFunction Label
The stack will now look like this:
The function reference entered earlier now points to a definition that takes the input and adds 3.
Fref used in recursion (Factorial Example)
Recursion occurs when a function calls itself with a new set of parameters. In the functional programming paradigm, recursion is essentially the replacement for looping. For instance, most of us are familiar with the factorial function, (e.g. Factorial(5) = 5*4*3*2*1 = 120). You could create a function to find the factorial of a number as follows:
x 1 > x x 1 - Fact fref * 1 ? Fact Label
5 Fact
Which would result in the following being on the stack:
Note how the function calls itself via a function reference. Note also the use of a Conditional expression (see below) when choosing whether or not to do the recursion. Recursions must always be inside of a conditional statement, or the recursion will try to repeat forever (but should fail after reaching the maximum recursions limit).
Passing in a function as an input to another function using Fref
Sometimes you may want to define a function which uses another function as an input. For instance, in calculus the approximation of a differential at a given point may be found using the formula:
f' = (f(x + Δx) - f(x))/Δx
In our case we will make a differential function hard coding Δx to .001 and letting f and x be inputs. Then we will call that function using two different kinds of inputs. Here are the commands we would use to create the function and to call it two different times:
x 0.001 + f fref x f fref - 0.001 / differential Label
"sin" PI 4 / differential
x Square 5 differential
The results were obtained with the angle mode set to radians and are not exact, but are a good approximation. Notice how in the first call to the differential function the value for f was passed as a string (string entries start with a quote and optionally end with one). This is necessary because otherwise sin would execute as soon as the word sin was entered. We could have also chosen to pass "sin(x)" as the function. For the second call to the differential function the function definition was passed in as an argument. So, functions may be defined elsewhere and passed in as a string, or the definition of the function itself may be passed in - either way works.
Conditional [?]
You only have to enter "?" to execute this function. The function evaluates an expression, and if the result for that expression is positive returns the designated True result, otherwise returns the designated False result. The stack inputs are:
Expression to Evaluate, True result, False result
Once entered, a conditional looks something like:
Expression to evaluate ? True result : False result
For example, to create an expression that would return the minimum of two values, one could use the ? function to create the following expression:
(A < B) ? A : B
To create this expression, the following calculator keystrokes would be entered:
A B < A B ?
Label
Labels a calculation or function so that it may be used by name in later calculations. Before using this function, the stack must contain an entry which is to be labeled followed by a name to be used for the label. The name may optionally be a string (enclosed in quotes). Using a string makes it possible to override on the stack an existing function in memory. There is a complete help page describing Names, Labels, and Functions and how they are used.
Unlike saving the calculation or function to memory a label only exists in the context of stack entries where they are used and does not remain in the memory menu.
>, <, ==, ...
Opens sub-menu to select comparison operators. Comparison operators return 1 if comparison is true, 0 otherwise. Comparison operators are useful in conditional expressions (see above).
and, or, ...
Opens sub-menu to select logic operators. For purpose of logic operations, all positive input values are treated as "true" values, zero and negative input values are treated as "false" values. The logic operators always output 1 for true and 0 for false.
In Out
These two button label inputs and outputs for Function Blocks.
seqr(i,f,s)
This operation generates a list with a range of numbers starting at i, running through f, with a step size of s. For instance, if the following commands are entered:
5 11 2 seqr
The result will be the following list:
{5, 7, 9, 11}
seqn(i,n,s)
This button generates a list of numbers starting at i with a count of n and a step size of s. It is similar to the above operation only number of list entries is specified instead of final entry value. For instance, if this button is pressed when the following is on the stack:
3 5 4 seqn
The result will be the following list:
{3, 7, 11, 15, 19}
Append
Appends an additional entry to a list, or a list to a list, or a regular stack entry to another stack entry to create a list.
Count
Returns number of entries in a list. If executed on a non-list entry, returns one.
{...}[i] - hot key is "["
Index into a list and return that element. Index is zero based (i.e., first element is element zero).
Random
Generates a random real number between 0.0 and 1.0.