错误"word is not bound to a context"是什么意思?



在Rebol 3中尝试单词时,我遇到了以下错误。

>> 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

由于以下结果,这似乎相当棘手:

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

我想知道,当一个词看起来与上面的完全相同时,它怎么不能与上下文绑定。。。

在Rebol 3中,控制台和脚本的某些行为对理解很重要:

您键入的任何内容都是Rebol生成的load。当它是load ed时,它被放在上下文中。

如果我键入:

b: 4
set 'b 5

存在一个现有的单词b'b,而没有任何正在评估的代码/数据,它被放在system/contexts/user上下文中,因此它与该上下文具有绑定。

>> 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...

为了表明这是相同的上下文:

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

但是,当您键入to-word "b"时,load看到的只是一个单词to-word和一个字符串。因此,在这种情况下,loadto-word字添加到system/contexts/user,但绑定b不会发生任何事情,因为它尚未加载。

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

此外,to word!(或to lit-word!等)在被评估时不绑定任何东西。该绑定必须手动完成。

请参阅如何在Rebol模块中绑定单词?有关更多信息,

最新更新