Go to the first, previous, next, last section, table of contents.


function definition syntax

A good notation makes things look simple by making common operations concise. It is good programming practice to make heavy use of function definitions (5).

In any event, Forth does an admirable job of making function definitions simple, cheap and concise, and Muq MUF attempts to preserve that heritage:

Stack:
: hi "Hello!\n , ;
Stack:
hi hi hi
Hello!
Hello!
Hello!
Stack:
: thrice 3 * ;
Stack:
13 thrice
Stack: 39
thrice
Stack: 117
thrice
Stack: 351

The first word after the colon is the name of the new function; The remaining words up until the ; form the definition of the function: Once the function is defined, entering its name is about the same as entering all the code in its body.

Muq MUF allows defineWord: as a synonym for :, regarding the latter as an abbreviation of the former. Ada programmers and lawyers may prefer the former name grin ...


Go to the first, previous, next, last section, table of contents.