Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Function Context Query

From: larry:ecotope at: 4-Dec-2001 12:06

Hi Mark, Joel, Just a couple of quick comments. The situation with function contexts is a bit confusing. I believe there are 3 stages involved. We can call them "load time", "function creation time", and "function application time". Consider the following:
>> a: "hello"
== "hello"
>> g: func [/local a][a] >> get first second :g
** Script Error: a has no value ** Near: get first second :g
>> unset? get/any first second :g
== true
>> g
== none
>> get first second :g
== none 1) load time The word 'a' in the body block [a] of the function definition has been bound to the global context before the function FUNC is executed, at this time it will be associated with the value "hello". 2) function definition time After func has run, a local context has been created in which the word 'a' has no value. It is unset. The body block is not evaluated at function definiton time, but is bound to the new context. 3) function application time Only after g has been executed, is the word 'a' set to NONE. The local words in the function only get values when the function is applied. If the values are determined by the arguments or refinements, or by the use of SET or a set-word in the body block; they assume that value, otherwise they are set to NONE. Cheers -Larry ----- Original Message ----- From: <[Robbo1Mark--aol--com]> To: <[rebol-list--rebol--com]> Sent: Tuesday, December 04, 2001 1:21 AM Subject: [REBOL] Re: Function Context Query
> Joel Neeely/ everybody, > > perhaps you misunderstood my previous post, > my concern was that uninitialised local words > are treated differently between contexts and > function-contexts. > > Please see below, > > >> use [my-word] [print unset? get/any 'my-word] > true > >> my-func: has [my-word] [print unset? get/any 'my-word] > >> my-func > false > >> my-func: has [my-word] [print none? get/any 'my-word] > >> my-func > true > >> > > In a use context they are initialised to the unset! value if they are not
set BUT in a function context they are initialised to the none! value and that's what bothers me.
> I don't see a reason or logic for the distinction, can anybody please
explain why these contexts are treated differently, as from what I can see it is possible to use uninitialised words in function contexts, well they're not actually uninitialised as REBOL sets them to 'none during function context creation,