REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 22-Nov-2013 Edit History |
The REBOL language contains a few different types of functions, including native!, action!, function!, and closure!. The main thing that makes them different is how they are evaluated.
The function! datatype is a higher level function that is interpreted. They are also called user-defined functions, and system functions defined this way are called mezzanine functions.
Functions consist of a specification and a body block. The specification part provides the interface specification and any embedded documentation. The body is the code of the function.
The formal definition of function is:
make function! [[specs] [body]]
(However, functions are normally created using helper functions. See below.)
The function specs block holds:
arguments | the arguments passed to the function. |
datatypes | optional datatype specifications for each argument. |
refinements | optional variations in the behavior and arguments of a function. |
doc strings | embedded documentation for the function and its arguments. |
For every argument it is possible to define how the argument is passed to the function using one of the formats:
Notation | Meaning |
---|---|
word | The argument expression is evaluated before it is passed to the function. |
'word | The argument expression is evaluated only if it starts with a get-word! or a paren!. |
:word | The argument expression is not evaluated. The very next value is used. |
word: | Reserved. Used to define variations. |
Normally, you create a function! using a helper function. There are a few choices:
func | Is the most common function defining function. |
funct | Is similar to func, but by default makes internal variables locals. |
has | Is for creating functions that have no formal arguments, only local variables. |
does | Is for creating functions that have no variables at all. |
More about functions is found in code: defining functions.
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |