This is documentation for the TOY.4TH file. These are some simple programs intended to help the novice learn Forth. ******************************************************************************* ******************************************************************************* ******************************************************************************* The calculation of parallel resistance was a demonstration program in ISYS Forth (for the Apple II computer). This just shows how to use the stack. Also, we can see how using the stack allows functions to be built on to of each other. Once we have a function PAR that calculates parallel resistance for two resistors, it is easy to write a function that calculates parallel resistance for three resistors: : 3par ( r1 r2 r3 -- r ) par par ; In C, such a function would be a big mess, with enough parenthesis to scare a Lisp programmer. Another thing that PAR demonstrates, is how the Forth interpreter can be used interactively. If you want to know the parallel resistance of three resistors, of 250, 300 and 120 milliohms, you can type: 0 250 300 120 ipars . The Forth system will respond: 63 ok This is not possible in C, because there is no interactive console. You would have to compile the program into an .exe, and you would have to write your own user-interface that obtained the data from the user and then displayed the result. This would be an awful lot of work for such a simple program. ******************************************************************************* ******************************************************************************* ******************************************************************************* The calculation of the Fibonacci sequence is a classic program for novices to write, so here it is in Forth. I think the recursive version is more readable, but the iterative version is likely faster on most systems. ******************************************************************************* ******************************************************************************* ******************************************************************************* The Towers of Hanoi program is another classic program for novices to write. The version of <HANOI> that uses local variables (it is commented out) is more readable, but the version that uses the parameter stack is likely faster on most systems. It is not too bad for readability considering how much data is being manipulated. As a general rule, I don't like to have more than three datums in use on the stack. This is a typical example of recursion in Forth. I usually have a high-level word (HANOI in this case) that preps a low-level word (<HANOI> in this case) which is recursive. As a convention, the low-level word has the same name as the high-level word but with pointy brackets around it. I don't have an iterative version of the Hanoi program, but that is possible --- I will leave it as an exercise for the reader for now.