在 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
和一个字符串。所以在这种情况下,load
将 to-word
词添加到 system/contexts/user
但绑定(bind) b
时没有任何反应> 因为它还没有被加载。
>> bound? to word! "b"
== none
此外,to word!
(或to lit-word!
等)在求值时不绑定(bind)任何东西。该绑定(bind)必须手动完成。
关于scope - 错误 "word is not bound to a context"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18419888/