What's difference between built-in FUNCTION and the FUNCS add-on?
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?
http://www.fm.vslib.cz/~ladislav/rebol/funcs.r
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
精彩评论