[REBOL] Re: basics: meaning and uses of make object! vs. context
From: ammon:rcslv at: 9-Jun-2002 15:15
Hi,
>> a: make object! [ blk: [print 'Hi] set 'f func [] [do blk]]
>> f
Hi
>> source f
f: func [][do blk]
The little bit above is an actual cut and paste from a fresh REBOL/Command
console on Linux RedHat 7.2 if you actually get something different
somewhere else please let us know.
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.
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"]
]
>> mold a
== {
make object! [
a: func [][print "making a"]
]}
>> form a
== "?object?"
>> probe 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!
HTH
Ammon
PS thanks to your post, I found that you can create a global word that has a
context different than the global context without using 'bind! Enjoy!!
A short time ago, Ingo Hohmann, sent an email stating: