REBOL Document

Function - Function Summary


Summary:

Defines a user function with local words.

Usage:

function spec vars body

Arguments:

spec - Optional help info followed by arg words (and optional type and string) (must be: block)

vars - List of words that are local to the function (must be: block)

body - The body block of the function (must be: block)

Description:

FUNCTION is identical to FUNC but includes a block in which you can name words considered LOCAL to the function.


    average: function [block] [total] [
        total: 0
        foreach number block [total: number + total]
        total / (length? block)
    ]
    print average [1 10 12.34]
    7.78

Related:

does - A shortcut to define a function that has no arguments or locals.
exit - Exits a function, returning no value.
func - Defines a user function with given spec and body.
function? - Returns TRUE for function values.
has - A shortcut to define a function that has local variables but no arguments.
make - Constructs and returns a new value.
return - Returns a value from a function.
use - Defines words local to a block.


<Back | Index | Next>

Copyright 2004 REBOL Technologies