[REBOL] Re: Obscure? You be the judge!
From: nitsch-lists:netcologne at: 14-May-2002 21:37
Hi Joel,
Am Dienstag, 14. Mai 2002 14:57 schrieb Joel Neely:
> Hi, Volker,
>
> Thanks for the explanations. As Larry Wall said:
>
> Just because something is obviously happening doesn't mean
> that something obvious is happening.
>
> ;-)
>
> However, I'm still left with a puzzled look on my face over
> one aspect of this...
>
> Volker Nitsch wrote:
> > Hi Joel,
> >
> > >> a: context [ b: [1]]
> > >> c: make a[]
> > >> d: make a[]
> > >> same? a/b c/b
> >
> > == false
> >
> > >> same? c/b d/b
> >
> > == false
> >
> > when you 'make an 'object!, all strings, blocks and functions are
> > copied.
> > that allows for example in 'layout :
> > box with[append init[my-inits]]
> > without destroying the original in box.
> > also blocks, like functions, are rebound.
> > so [make child-proto []] gives a copy of 'dataref, not the original.
> > but objects are not copied,
> > so the 'face/feel are all the same after [make face[]].
> > or in your case,
>
> (Oh, by the way, did you find this documented anywhere, did you
> just figure it out for yourself, or is there another path to
> enlightenment? ;-)
>
Meditation, tea and trying everything out ;)
> Thanks to your explanation, I have a more compact example...
>
> gub?: make object! [
> data: [1]
> proto: make object! [
> number: 0
> dataref: data
> speak: func [] [print [number mold dataref]]
> ]
> things: []
> append things make proto [number: 1]
> append things make proto [number: 2 dataref: data]
> tweak-n-speak: func [blk [block!]] [
> insert data blk
> foreach thing things [thing/speak]
> ]
> ]
>
> ...which behaves as follows...
>
> >> gub?/tweak-n-speak ["OK,"]
>
> 1 [1]
> 2 ["OK," 1]
>
> My remaining puzzlement is over this contrast:
>
> If I accept the description that (during the construction of
> GUB?/PROTO) GUB?/DATA is copied and GUB?/PROTO/DATAREF is set
> to refer to the copy, then that explains the behavior of
> GUB?/THING/1 .
>
> However, during the construction GUB?/THING/2 the additional
> spec block *also* refers to GUB?/DATA , but apparently the copy
> behavior does *not* occur (even though the referenced data value
> is still only a block).
>
> This makes me wonder if the issue here is a difference in the
> evaluation of the specblock parts of
>
> make object! [...specblock...]
>
> vs.
>
> make some-object [...specblock...]
>
All pure sientific, no magic needed.
before a spec-block is executed, it is parsed for set-words.
only the contents of set-words are copied.
here:
append things make proto [number: 1]
append things make proto [number: 2 dataref: data]
you see there is no set-word for 'data, so it remains untouched.
the copying happens before execution, so you get a copy
append things make proto [number: 2 ? dataref dataref: data]
but then overwrite it with the original
append things make proto [
number: 2 ? dataref dataref: data ? dataref
]
the trick used for "export" is based on that.
context[
set 'something-outside "this will not be part of new context"
]
'something is no set-word, so it will not be included in the new context,
so the outside word stays bound and goes modified.
> This is uncomfortably reminiscent of FORTH, in which one must
> have a complete operational model of the interpreter's internal
> state if one is to understand the behavior the more advanced
> (and hence more useful) aspects of the language. At least FORTH
> had both liberal documentation and available source to help with
> the construction/communication of such an operational mental
> model...
>
no state and immediate words needed in rebol.
I know this should be impossible :)
> -jn-
greetings
-Volker