REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 22-Nov-2013 Edit History  

REBOL 3 Datatypes: Function!



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.)

Changed from R2

Note that this format changed from REBOL V2. This change was necessary because make accepts only two arguments. Therefore, the second argument contains the specs block and the body block.

The function specs block holds:

argumentsthe arguments passed to the function.
datatypesoptional datatype specifications for each argument.
refinementsoptional variations in the behavior and arguments of a function.
doc stringsembedded 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:

funcIs the most common function defining function.
functIs similar to func, but by default makes internal variables locals.
hasIs for creating functions that have no formal arguments, only local variables.
doesIs for creating functions that have no variables at all.

More about functions is found in code: defining functions.

  TOC < Back Next > - WIP Wiki Feedback Admin