[REBOL] Re: Function Context Query
From: rotenca:telvia:it at: 6-Dec-2001 16:27
> WHY is setting words in functions to 'none by default useful?
When you create the function, all the words (args, refinements, args of
refinements) are binded at a new hidden context and the starting value of
words in context is the unset value.
When you execute the function, all the args and refinements and args of
refinements are set to none if they are not used in the function call. It is
more easy to test a none value of an unset value (none = false for
The so called "locals words" of a function are only arguments of the
refinement 'local, so they are set to none like any other argument not used in
the function call.
> Why is the ability to use apparently unset words a desirable feature?
> Does this not confuse the language in that words cannot be used until after
they have been defined?
An unset word is a word with the value unset. It is like any other value and
any other word. If you use it where a function ask a value, Rebol triggers an
error. But Rebol triggers the same error if you pass an argument of type
integer! where a function ask for a value of type unset:
>> x: func [a [unset!]][value? 'a]
>> do [x ()]
>> do [x 1]
** Script Error: x expected a argument of type: unset
** Near: x 1
BTW, I think that the name of function value? is confusing. It should be
something like: not-unset-value?
And also unset is confusing, because you can set a word at the unset value:
>> set/any 'a ()
>> value? 'a
my conclusion: unset <> no value
A true word without value is a word out of context which trigger the error:
"is not defined in this context"
> Now we have another "exception" case for words in functions.
> What makes words in functions different from global words or words in
objects or words in a use context?
That they are also arguments. Functions are not contexts, they only use a
context to mask the global context from the value of their arguments.