REBOL 3 - 在哪里可以访问用户定义的命名空间字?

时间:2013-07-18 03:22:03

标签: rebol rebol3

让我们说几句话:

Word1: 5
Word2: "blahdiddyblah"

系统中是否存在某些部分或块存储正在使用的单词?

尝试过这样的事情,但失败了:

S1: to-block copy system/contexts/user

D: 3

S2: to-block copy system/contexts/user

Difference s1 s2

根据@johnk的建议,我试过:

>> snapshot-of-words: words-of system/contexts/user
== [system snapshot-of-words words-of contexts user]

>> x: 1
== 1

>> difference snapshot-of-words words-of system/contexts/user
== [x difference]

>> difference snapshot-of-words words-of system/contexts/user
== [x difference]

>> 5 + 9
== 14

>> form ["hellow" "there" ]
== "hellow there"

>> difference snapshot-of-words words-of system/contexts/user
== [x difference + form]

这是什么意思?本机函数在使用后被绑定到用户上下文中?有没有办法将这些与用户可能绑定的方法隔离开来?

1 个答案:

答案 0 :(得分:5)

当您在脚本中使用单词时 - 您以交互方式输入的每个命令行都是不同的脚本 - 这些单词将添加到用户上下文system/contexts/user中。只需在脚本中添加单词就可以将它们添加到用户上下文中,这就是所需的全部“用途”。如果lib(运行时库)中已存在这些新单词中的任何一个,则用户上下文单词将从当时运行时库中这些单词的值中分配初始值。

在您的示例代码中,当您在脚本中使用单词form时,它将添加到用户上下文中。然后为form分配当时分配lib/form的值。从那时起,form是一个用户词 - 系统词是lib/form

单词的值从lib传播到用户上下文的唯一时间是该单词首次添加到用户上下文并给出其初始值。之后,如果您希望对该单词的lib版本进行任何更改以使其成为该单词的用户上下文版本,则必须自行分配。如果它们具有相同的值,那么这只是因为您没有为用户或系统词语分配新值。

用户上下文中的所有单词都是用户创建的单词,甚至是从lib初始化的单词。用户在将这些单词放入用户脚本时会生成这些单词。这是用户上下文的重点。因此,如果您在脚本中使用print,那就是用户词,与其他任何用户词都没有区别。

您可能需要查看此处了解详情:How are words bound within a Rebol module? 在这里:What is the summary of the differences in binding behaviour between Rebol 2 and 3?