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

Set with context (was Global function defined in context)

 [1/4] from: reboler:ifrance at: 27-Dec-2002 17:08


Hi List, 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".
>> myWorld: context [
[ a: 10 [ set 'helloA func [][print ["Hello " a]] [ ]
>> >> a: 20
== 20
>> helloA
Hello 10 The HelloA function, however global, is looking first in the context where it comes from. Am I right? Patrick

 [2/4] from: ammon::addept::ws at: 27-Dec-2002 10:10


HI, Yes you are right...
>> myWorld: context [
[ a: 10 [ set 'helloA func [][print ["Hello " a]] [ ]
>> helloA
Hello 10
>> myWorld/a: 100
== 100
>> helloA
Hello 100
>> myWorld: context [
[ set 'helloA func [][print ["Hello " a]] [ ]
>> a: 20
== 20
>> helloA
Hello 20 HTH Ammon Johnson CIO of Addept ---------- (www.addept.ws) 435.616.2322 ---------- (ammon AT addept.ws)

 [3/4] from: lmecir:mbox:vol:cz at: 31-Dec-2002 14:48


Hi Pat,
> 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 contained 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. Regards -L Happy New Year to all!

 [4/4] from: reboler:ifrance at: 31-Dec-2002 18:10


Hi Ladislav, Good to see you back and thanks for all this. It seems all clear now. With you, It is always good to be wrong ! Happy New Year to all Patrick