REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 11-Mar-2014 Edit History |
Defines a user function with local words.
Arguments:
spec [block!] - Optional help info followed by arg words (and optional type and string)
vars [block!] - List of words that are local to the function
body [block!] - The body block of the function
See also:
This is similar to func, except all set-words are assumed locals. This way, it's not necessary to specify the /local part of the spec, although you still can.
Example:
average: function [block] [
total: 0
foreach number block [total: number + total]
total / (length? block)
]
print average [1 10 12.34]
7.78
total
** Script error: total has no value
If you still desire to create non-local values in the function, use set to set words:
f: function [a] [
b: a
set 'c b / 2
]
f 7
3.5
c
3.5
If c still needs to be local, you can add the local refinement:
unset 'c ; make sure it's not set
f: function [a /local c] [
b: a
set 'c b / 2
]
f 7
3.5
c
** Script error: c has no value
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |