Next: COD Files Up: COD Previous: Interactive mode
When running COD interactively,
it is sometimes necessary to enter the same sequence of tokens several times.
For such cases, you should create a colon definition
that contains the sequence.
A colon definition consists of a colon
COD> : X2 DUP * ;which will have the effect of multiplying the top number on the stack by itself. After you have defined
COD> 3.0 X2 9.0A previously defined colon function may be used in the definition of a new colon function. An
COD> : X3 DUP X2 * ; 9.0 COD> 3.0 X3 9.0 27.0The name of a colon function is not allowed to match the name of any built-in function or other colon function. Hence, a colon function cannot be used to redefine the action of any existing COD keyword.
It is possible to enter a multi-line colon definition interactively. While in the midst of a multi-line colon definition, the stack will not be printed just before the COD prompt. The following example shows one way to enter a colon definition that prints the integers from one to five:
COD> : COUNT5 COD> 5 1 FOR COD> I . COD> LOOP COD> ; 9.0 27.0 COD> COUNT5 1.0 2.0 3.0 4.0 5.0 9.0 27.0The last line, just before the next COD prompt, is the stack. This allows us to verify that the original stack has been changed, and therefore, COUNT5 is not altering the stack.
Web Page Maintained by: Dr. Lawrence E. Brown email@example.com