Question

In experimenting with words in Rebol 3, I ran into the following error.

>> set to lit-word! "g" 4
** Script error: 'g word is not bound to a context
** Where: set
** Near: set to lit-word! "g" 4

This seems pretty tricky because of the following results:

>> to lit-word! "g"
== 'g
>> set 'g 4
== 4

I was wondering how a word cannot be bound to a context when it looks identical to the above...

Was it helpful?

Solution

In Rebol 3 there is certain behavior of the console and scripts that is important to understand:

Anything you type is loaded by Rebol. When it is loaded, it is put in a context.

If I type:

b: 4
set 'b 5

There is an existing word b or 'b without any of the code/data being evaluated, which is put in the system/contexts/user context, so it has binding to that context.

>> bound? 'b
== make object! [
    system: make object! [
        version: 2.101.0.3.1
        build: 31-May-2013/18:34:38
        platform: [
            Windows win32-x86
        ]
        product: 'saphir-view
        license: {Copyright 2012 REBOL Technologies
            REBOL is a trademark of REBOL Technologies
            Licensed under the Apache License, Version 2.0.
            See: http://www.apache.org/licenses/LICENSE-2.0
        }
        catalog: make object! [
            datatypes: [end! unset! none! logic! integer! decimal! percent! mo...

And to show this is same context:

>> same? (bound? 'b) system/contexts/user
== true

However, when you type to-word "b", all that load sees is a word to-word and a string. So in this case load adds the to-word word to system/contexts/user but nothing happens with binding b because it hasn't been loaded.

>> bound? to word! "b"
== none

Moreover, to word! (or to lit-word!, etc.) when evaluated does not bind anything. That binding must be done manually.

See How are words bound within a Rebol module? for more information

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top