[REBOL] Re: basics: meaning and uses of make object! vs. context
From: ingo:2b1 at: 11-Jun-2002 19:30
Hi Ammon,
Ammon Johnson wrote:
>>>a: make object! [ blk: [print 'Hi] set 'f func [] [do blk]]
>>>f
>>
> Hi
>
>>>source f
>>
> f: func [][do blk]
>
<..>
> I don't see what you are talking about, I didn't see any lost code. Source
> delivered to you EXACTLY what you asked for, the very source of 'f. What is
> the difference between the example above and the example below? (again this
> is from a fresh console)
>
>>>set 'f func [] [do blk]
>>>blk: [print 'Hi]
>>
> == [print 'Hi]
>
>>>source f
>>
> f: func [][do blk]
>
>>>f
>>
> Hi
>
> basically nothing. In the previous example the Global word 'f was set when
> the spec block of 'a was evaluated by 'make. In this example f was set at
> the commandline. The reason that 'f does the value of a/blk in your example
> is because 'f was created in the *context* of a, or in other words the words
> within the 'a object are *local* to 'f. I am not sure what you were
> expecting to see when you typed "source f" at the commandline, but you saw
> the actual source of 'f.
You are right, there is no _basic_ difference, between the two.
What I wanted to illustrate is, that you can't understand what 'f is
doing, without knowing the content of 'blk. And the content of 'blk, in
my example, is hidden in a different context, so 'source won't tell you
about it.
A real world example:
>> source request-date
request-date: func ["Requests a date." /offset xy][
if none? base [init]
either offset [inform/offset date-lay xy] [inform date-lay]
base
]
Can you tell me what this function will be doing, from viewing the
'source output, alone? I guess not.
> That said, I think that what you are refering to is the fact that when you
> pass a block to make as you did in your example the block is evaluated and
> any commands given are done, any values that are not assigned to words with
> in the spec block are lost for example.
>
>>>a: make object! [
>>
> [ print "making a" ; this line will be lost
> [ a: does [print "making a"] ;this will not
> [ ]
> making a
>
>>>source a
>>
> a:
> make object! [
> a: func [][print "making a"]
> ]
>
<..>
> Do you see what I am saying? SOURCE will even give you the the very SOURCE
> of an Object! (something I wasn't fully aware of) Go ahead, use the SOURCE
> faithfully it. It will not fail you LUKE!
Then, have you tried to 'source the 'a object! from above?
>> source a
a:
make object! [
blk: [print 'Hi]
]
(or probe, or whatever ...)
Sometimes theres more to the SOURCE than meets the eye :o)
Ingo
P.S: probe req-funcs/reg-date ;to get the missing link for request-date.