[REBOL] Re: Set with context (was Global function defined in context)
From: lmecir:mbox:vol:cz at: 31-Dec-2002 14:48
> More on 'set with context, just to be sure...
> A 'set construction, like the following, is used to define a global
function using local (variable) "variables".
It looks correct at the first sight. The trouble is, that you could define
the word 'helloA to refer to any Rebol value, like
set 'helloA 2003
, e.g. A sentence like "define a global integer..." can reveal, that there
is something wrong with it. Integers (like functions) aren't global or
local. The important thing that will be global in this case will be the word
'helloA, which will refer to the function in question.
> >> myWorld: context [
> [ a: 10
> [ set 'helloA func [print ["Hello " a]]
> [ ]
> The HelloA function, however global, is looking first in the context where
it comes from.
> Am I right?
No. The HelloA function is neither global nor local, it is just a function.
Moreover, a function doesn't have to "look" into any context:
The function has got its body block, which contains words. The words
in the body of the function have their context information,
every word has its own context information. That is how the proper context
is known when the function is executed.
Happy New Year to all!