REBOL 3-在哪里可以访问用户定义的名称空间单词? [英] REBOL 3 - Where can user defined namespace words be accessed?

查看:97
本文介绍了REBOL 3-在哪里可以访问用户定义的名称空间单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我定义了几个词:

Lets say I define a few words:

Word1: 5
Word2: "blahdiddyblah"

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

Is there some part or block of the system that stores which words are in use?

尝试过类似的操作,但失败了:

Tried something like this but it failed:

S1: to-block copy system/contexts/user

D: 3

S2: to-block copy system/contexts/user

Difference s1 s2

根据@johnk的建议,我尝试了:

According to @johnk suggestion, I tried:

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

这是什么意思?使用后将本机函数绑定到用户上下文中吗?有没有办法将它们与用户可能绑定的对象区分开?

What does this mean? native functions are bound into the user context after use? Is there a way to isolate these from those a user might bind?

推荐答案

在脚本中使用单词时-交互输入的每个命令行都是不同的脚本-这些单词将添加到用户上下文system/contexts/user中.只需将脚本中的单词全部添加到用户上下文即可,这就是所有需要的使用".如果运行时库lib中已经存在这些新单词中的任何一个,则用户上下文单词将从当时这些单词在运行时库中具有的值中获得初始值.

When you use words in a script - every command line you enter interactively is a different script - those words are added to system/contexts/user, the user context. Simply having the words in the script at all gets them added to the user context, that is all the "use" that is needed. If any of these new words already exist in lib, the runtime library, then the user context words get their initial values assigned from the values that those words have in the runtime library at that moment.

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

In your example code, when you use the word form in your script it is added to the user context. Then form is assigned the value that lib/form is assigned at the time. From then on, form is a user word - the system word is lib/form.

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

The only time that the values of words propagate from lib to the user context is when that word is first added to the user context and given its initial value. After that, if you want any changes in the lib version of that word to make it into the user context version of that word, you have to assign it yourself. If they have the same value going forward then it is just because you haven't assigned a new value to either the user or system words.

用户上下文中的所有单词都是用户创建的单词,甚至包括从lib初始化的单词.用户将这些词放在用户脚本中时就做出了这些词.这就是指向用户上下文的全部内容.因此,如果您在脚本中使用print,这是一个用户词,与其他用户词没有区别.

All words in the user context are words that the user made, even the ones that were initialized from lib. The user made those words when they put them in user scripts. That is the whole point to the user context. So, if you use print in your script, that is a user word, no different from any other user words.

您可能希望在此处查看更多详细信息:单词如何在Rebol模块内绑定? 在这里也是:

You might want to look here for more details: How are words bound within a Rebol module? And here too: What is the summary of the differences in binding behaviour between Rebol 2 and 3?

这篇关于REBOL 3-在哪里可以访问用户定义的名称空间单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆