REBOL 3.0

BIND expands contexts

Carl Sassenrath, CTO
REBOL Technologies
16-May-2006 23:28 GMT

Article #0026
Main page || Index || Prior Article [0025] || Next Article [0027] || 9 Comments || Send feedback

Here is something for you to think about in REBOL 3.0:

obj: make object! [a: 1]
word: bind 'b obj
set word 10
print obj
a: 1
b: 10

The bind function not only bound the word to the context, it actually added it to the context.

This result comes as a side effect from this: REBOL 3.0 does not use a global context environment; it uses modular contexts.

This means that the expression:

word: make word! "xyz"

creates a word (symbol) 'xyz, but not a variable. That is reasonable because a symbol can stand alone (a useful thing), but a variable requires a context. The make word! function specifies no context, so no context is assumed. If you try to use it:

set word 10
**Script Error: xyz word has no context (not bound)

In REBOL 3.0 the default behavior for bind is to bind the word to the context regardless of what it takes to make that happen (a behavior that is required for modules to work as new word definitions are created via additional scripts, etc.)

A few of you will ask: why does this matter? The main reason is memory (something we are optimizing on R3.0). Why force allocation for "free" variables (module variables) that are never used?

Some of you may have feedback to this, so post it. This is not set in concrete... yet.

9 Comments

REBOL 3.0
Updated 23-Nov-2024 - Edit - Copyright REBOL Technologies - REBOL.net