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

标签 scope rebol rebol3

在 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

我想知道当一个词看起来与上面相同时,怎么不能将其绑定(bind)到上下文...

最佳答案

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

您键入的任何内容都由 Rebol 加载。当它被加载时,它被放入一个上下文中。

如果我输入:

b: 4
set 'b 5

存在一个词 b'b 没有任何被评估的代码/数据,它被放在 system/contexts/user 上下文,所以它绑定(bind)到那个上下文。

>> 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 但绑定(bind) b 时没有任何反应> 因为它还没有被加载。

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

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

参见 How are words bound within a Rebol module?了解更多信息

关于scope - 错误 "word is not bound to a context"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18419888/

相关文章:

arrays - 将指针放入数组的正确方法?

tdd - Rebol Saphirion GUI 测试驱动开发 (TDD)

rebol - 什么是 REBOL 结构!数据类型?

rebol - 使用 Rebol 3 FFI 包装共享变量

Rebol 3 - 如何使用 Saphirion 的 Rebol 的 view/new 的等效项进行调试

C++ 'vector' 未在此范围内声明

java - spring中@Configuration类的作用域

javascript - 调试显示模块模式 : functions not in scope until called?

rebol - 如何将密码与mysql ://protocol in Rebol?连接起来

serial-port - 在 Rebol3 中读取串口