COLLECT-WORDS
Moving forward with finishing a few more of the required native functions, collect-words has been added. It exports the internal mechanism used for building contexts, such as objects, modules, and functions.
The main advantage of collect-words function is that it is linear, not N squared where N is the number of words, nor does it require hashing overhead. The secondary advantage is that word collection is generally useful in REBOL, so you don't need to write your own now.
USAGE:
COLLECT-WORDS block /deep /set /ignore words
DESCRIPTION:
Collect unique words used in a block (used for context construction).
COLLECT-WORDS is a native value.
ARGUMENTS:
block (block!)
REFINEMENTS:
/deep -- Include nested blocks
/set -- Only include set-words
/ignore -- Ignore prior words
words -- Words to ignore (object! block!)
For example, the funct function needs to collect all set words and make the local variables, but avoid collecting the functions argument variables. Its code becomes:
funct: func [
{Defines a user function assuming all set-words are locals.}
spec [block!] {Help string (opt) followed by arg words (and opt type and string)}
body [block!] {The body block of the function}
][
spec: copy/deep spec
body: copy/deep body
unless find spec /local [append spec /local]
append spec collect-words/deep/set/ignore body spec
make function! reduce [spec body]
]
9 Comments
|