REBOL 3.0

Comments on: COLLECT-WORDS

Carl Sassenrath, CTO
REBOL Technologies
24-Apr-2009 14:56 GMT

Article #0193
Main page || Index || Prior Article [0192] || Next Article [0194] || 9 Comments || Send feedback

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

Comments:

Brian Hawley
24-Apr-2009 13:14:23
This is great news! That linear algorithm sounds really interesting...
-pekr-
24-Apr-2009 13:25:57
I know that you have final go on the names, but is 'set a good name for the meaining of the refinement? I can think about it as "those words, that are set", but at first sight it seemed to me, that function is going to set something. I have alternative name - /setwords, or /only
Brian Hawley
24-Apr-2009 15:45:31
That's what the /set refinement means in BIND too.
Carl Sassenrath
24-Apr-2009 19:10:41
As a historical side-note, the general method was suggested by Ladislav at the REBOL Milan devcon, but it was too big a change for R2, so I was determined to make sure it was in R3.

Man... I miss devcon.

-pekr-
24-Apr-2009 19:16:43
Carl, Prague awaits you. I think that it is already late to plan on autumn DevCon, and lot's of work to do in R3 area. Maybe we should start to think about Spring 2010 one next year - one year to prepare, and at least 3.0 will be surely out and in the wild ...
Steeve
25-Apr-2009 1:46:24
The /deep refinement allow to treat multi-dimentionnal data. Time to add it up in other block treating functions to power up our applications.

- foreach/deep - find/deep - select/deep - ...

Brian Hawley
25-Apr-2009 10:42:11
The problem with the /deep refinement is that for the purposes you mention, Steeve, going too deep is just as bad as not going deep at all. You need a way to specify the depth you want to go. This will let you distinguish between nested blocks that are structure, and those that are data.
Gregg Irwin
6-May-2009 14:28:16
I thought the same thing as Pekr.

Why does BIND use /ONLY instead of the more common /DEEP model?

Brian Hawley
6-May-2009 15:57:03
For BIND, /deep is the common case. This is a classic case of the standard option /only: Do the common case by default, use /only for the precise and/or weird stuff.

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

R3-0193


Comment:


 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

REBOL 3.0
Updated 26-Apr-2017 - Edit - Copyright REBOL Technologies - REBOL.net