Giuseppe:
> Hello, I am starting my experiments with Rebol. I want to write a small
> application to learn more about Rebol objects.
Your mental model is that derived from Smalltalk: methods and classes or
instances.
REBOL's objects do not work that way. They are more akin to being private
name spaces. The alternative name 'context is a better choice in that respect.
In REBOL you create an object. Then you can mint additional instances of it.
Generally, they do not share any values, so:
template: make object! [
f1: func [a b] [a + b]
f2: func [a b] [a * b]
v1: now
v2: []
v3: copy []
]
You can now create several instances of this:
inst1: make template []
inst2: make template [v1: 5-nov-2004]
inst3: make inst2 [f2: none]
You can see that that have no values in common:
inst1/v2 is not the same as inst2/v2
same? inst1/v2 inst2/v2
== false
And, crucially for your mental model:
inst1/f1 is not the same as inst2/f1:
(get in inst1 'f1) = (get in inst2 'f1)
== false
(mold get in inst1 'f1) = (mold get in inst2 'f1)
== true
So if you have functions in your object, they will be replicated in all its
instances. Not a good way to save space.
I tend to have a "function object" which you could think of as the method,
and a set of "variable objects" that contain the data.
Sunanda.
--
To unsubscribe from the list, just send an email to
lists at rebol.com with unsubscribe as the subject.