Library of Sample Programs
The following programs are some examples to show how functional programs may be written. If you want to examine them the best option is to load them into the calculator since a sequence of RPN commands can be pretty hard to interpret. You can load each program into the clipboard using the button and then paste them into the calculator on your local computer, or you can run the program on the web using the provided links.
Contributions
Any contributions to this library would be much appreciated. If you save your function to a file (see the hamburger menu) and send them to the developer (john@linstrum.net), your program will be displayed on this page with attribution.
List Manipulation
The following programs manipulate lists.
ReverseList
This program reverses the order of a list (i.e. {1, 2, 3} becomes {3, 2, 1}).
{ "Reverses item order in list" Description { { list finalIndex } In list finalIndex [ finalIndex 0 > ( list finalIndex 1 - ) finishReverse fref { } ? Append Out } "finishReverse" Label list In list list Count 1 - finishReverse Out } "ReverseList" Label { 1 2 3 4 } ReverseList
Programs for Teachers
The following programs were written primarily for use by math teachers.
Expand
This program turns the number "12.34" into the set "{10, 2, 0.3, 0.04}". Not very useful in itself, it is very useful as a sub-function in some of the programs below.
{ "Turns 12.34 into {10 2 0.3 0.04}" Description { { number tolerance } In number Log Truncate TenToPower "tenPower" Label number tenPower / Truncate tenPower * "nextExpand" Label number nextExpand Mod "remainder" Label remainder Abs tolerance > nextExpand ( remainder tolerance ) DoExpand fref Append nextExpand ? Out } "DoExpand" Label number In number number 1E-10 * DoExpand Out } "Expand" Label 123.456 Expand
LongMult
This program shows all of the intermediate results for long multiplication. For teachers it is useful for checking a student's work or for creating answer keys. Unfortunately, the intermediate results are shown horizontally, not vertically, but the information is there. This function calls the Expand and ReverseList functions so they must be on the stack or in the Mem Menu for the LongMult function to work properly.
{ "Shows intermediate products of long multiplication" Description { factor1 factor2 } In "Sum " factor1 factor2 Expand ReverseList * ToString " = " + factor1 factor2 * + + Out } "LongMult" Label 12 34 LongMult
LongDiv
This program shows all of the intermediate results for long division. The output format is less than ideal, but usable:
- The intermediate operations are listed horizontally instead of vertically.
- The intermediate results include place holder zeros which are usually left out of student work.
This function calls the Expand function so it must be on the stack or in the Mem Menu if the LongDiv function is to work properly.
{ "Shows intermediate results of long division" Description { { remainder divisor expandedQuotient indexer } In divisor expandedQuotient indexer [ * "subtrahend" Label remainder subtrahend - "newRemainder" Label " - " subtrahend + " = " + newRemainder + indexer expandedQuotient Count 1 - >= " " ( newRemainder divisor expandedQuotient indexer 1 + ) doNext fref ? + Out } "doNext" Label { dividend divisor } In dividend divisor / "quotient" Label quotient " : " + dividend + dividend divisor quotient Expand 0 doNext + Out } "LongDiv" Label 4422 11 LongDiv