REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: funct

funct  spec  body  /with  object

Defines a function with all set-words as locals.

Arguments:

spec [block!] - Help string (opt) followed by arg words (and opt type and string)

body [block!] - The body block of the function

Refinements:

/with - Define or use a persistent object (self)

object [object! block! map!] - The object or spec

Description

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:

f: funct [a] [
    b: a
]
f 7
7
b
** Script error: b has no value

If you still desire to create non-local values in the function, use set to set words:

f: funct [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: funct [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