Global function defined in context
[1/4] from: reboler::ifrance::com at: 26-Dec-2002 19:50
Hi, List Until recently I thought that the two following constructions were equivalent. 1. myWorld: context [ set 'helloWorld func [print "Hello World"] ] 2. myWorld2: context [ helloWorld2: func [print "Hello second World"] ] In fact, it is not. From (1.) we get a global function, from (2.) a local function.
** Script Error: helloWorld2 has no value ** Where: do-boot ** Near: helloWorld2
Hello second World Does 'set always create global function? if so, wouldn't it be better if documented in "HELP SET"? Patrick _____________________________________________________________________ GRAND JEU SMS : Pour gagner un NOKIA 7650, envoyez le mot IF au 61321 (prix d'un SMS + 0.35 euro). Un SMS vous dira si vous avez gagné. Règlement : http://www.ifrance.com/_reloc/sign.sms
[2/4] from: al:bri:xtra at: 27-Dec-2002 8:35
> 1. > myWorld: context [
<<quoted lines omitted: 4>>> helloWorld2: func [print "Hello second World"] > ]
3. myWorld3: context [ helloWorld: none set 'helloWorld func [print "Hello World"] ]
>> probe myWorld3
make object! [ helloWorld: func [print "Hello World"] ]
> Does 'set always create global function?
No. Evaluation of 'func creates a function! value. 'set takes the second value and assigns that value as the value of the first value (a word! value). Rebol looks for a matching word in the "closest" enclosing context. If none is found, Rebol creates a word in the global context. Andrew Martin ICQ: 26227169 http://valley.150m.com/
[3/4] from: nitsch-lists:netcologne at: 26-Dec-2002 23:43
>Hi, List >Until recently I thought that the two following constructions were equivalent.
<<quoted lines omitted: 17>>>Does 'set always create global function? >if so, wouldn't it be better if documented in "HELP SET"?
No, set-words allways create local-functions. because 'context looks for them. 'set is a trick for export, 'context sees no set-word, 'context ignores it. a: context[ a-func: none b: context[ set 'a-func func['a] b-func: func['b] ] ] ? a make object! [ a-func: func ['a] b: make object! [ b-func: func ['b] ] ]
[4/4] from: reboler:ifrance at: 27-Dec-2002 14:57
Hi Andrew, Thanks for the explanations. If I understand you (and Volker) well the 'set construction is merely a trick to define a not-in-context function. From recent Carl S. posts, he seems to use it a lot. Patrick
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted