内置 FUNCTION 和 FUNCS 附加组件有什么区别?
Rebol 3 中有一个FUNCTION 的新实现,它允许将变量自动绑定到默认情况下是本地上下文。
FUNCTION好像和VALUE有问题?测试,因为即使变量尚未在运行时设置,它也会返回 TRUE:
foo: function [] [
if value? 'bar [
print [{Before assignment, bar has a value, and it is} bar]
]
bar: 10
if value? 'bar [
print [{After assignment, bar has a value, and it is} bar]
]
]
如果您调用 FOO,您将得到:
Before assignment, bar has a value, and it is none
After assignment, bar has a value, and it is 10
这不是 FUNC 的工作方式(它只表示 BAR 在赋值后有一个值)。但是 FUNC 不会自动使变量成为本地变量。
我在 Ladislav Mecir 创建的库中找到了 FUNCS 原语。它有何不同,是否有相同的缺点?
There is a new implementation of FUNCTION in Rebol 3, which allows making variables automatically bound to local context by default.
FUNCTION seems to have a problem with the VALUE? test, as it returns TRUE even if a variable has not been set at runtime yet:
foo: function [] [
if value? 'bar [
print [{Before assignment, bar has a value, and it is} bar]
]
bar: 10
if value? 'bar [
print [{After assignment, bar has a value, and it is} bar]
]
]
If you call FOO you will get:
Before assignment, bar has a value, and it is none
After assignment, bar has a value, and it is 10
That is not the way FUNC works (it only says BAR has a value after the assignment). But then FUNC does not make variables automatically local.
I found the FUNCS primitive here, in a library created by Ladislav Mecir. How is it different, and does it have the same drawbacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主要区别在于,FUNCTION 深度搜索正文中的设置词,而 FUNCS 只是浅层搜索。 FUNCS 还使用略有不同的规范。
FUNCS 已经存在相当长一段时间了(不过不久前发生了更名)。
那个值?函数“问题”与函数的局部变量(即使您使用 FUNC 和 /LOCAL 来显式声明它们)被初始化为 NONE 这一事实有关。这导致了价值?即使变量“尚未初始化”,函数也会产生 TRUE。
一般来说,我不认为这种“用 NONE 初始化”有什么“大不了”,尽管这种行为与全局变量或对象变量的行为不同
The main difference is, that FUNCTION deep-searches for set-words in the body, while FUNCS just shallow-searches for them. FUNCS also uses a slightly different specification.
FUNCS has been around for quite some time (a name change occurred not long ago, though).
That VALUE? function "problem" is related to the fact that the local variables of functions (even if you use FUNC with /LOCAL to explicitly declare them) are initialized to NONE. That causes the VALUE? function to yield TRUE even when the variables are "not initialized yet".
Generally, I do not see this "initialized with NONE" a "big deal", although this behavior is not the same as the behavior of either global or object variables