[REBOL] Re: Global function defined in context
From: nitsch-lists:netcologne at: 26-Dec-2002 23:43
pat665 wrote:
>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.
>
>>>helloWorld2
>>>
>** Script Error: helloWorld2 has no value
>** Where: do-boot
>** Near: helloWorld2
>
>>>myWorld2/helloWorld2
>>>
>Hello second World
>
>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]
]
]