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


Arity declarations

It is traditional Forth programming practice to include at the start of each function a comment giving the number of arguments it accepts and returns. (This sort of documentation is a good habit in any language.)

Muq MUF continues this tradition, but extends it by making the declarations in a syntax understandable to the muf compiler, as do most modern languages other than Forth:

Stack:
: x { $ $ -> $ } * ;
Stack:
2 3 x
Stack: 6

The arity declaration is enclosed in curly braces and contains one '$' for each input parameter, followed by an arrow, followed by one dot for each value returned.

Muq distinguishes single arguments from blocks of arguments:

Stack:
: |double   { [] -> [] }   |for i do{ i 2 * -> i }   ;
Stack:
5 seq[
Stack: [ 0 1 2 3 4 |
|double
Stack: [ 0 2 4 6 8 |

The arity declaration contains one [] for each block read, and one for each block returned. Block arguments must in each case precede nonblock arguments.


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