[self-interest] Re: A stupid question

Jecel Assumpcao Jr jecel at merlintec.com
Tue Dec 7 13:49:50 UTC 1999


Hi, Mikael.

The title of this paper says it all:

   "Parents are Shared Parts: Inheritance and Encapsulation in Self"
   by Craig Chambers, David Ungar, Bay-Wei Chang, and Urs Hölzle
   http://self.sunlabs.com/papers/parents-shared-parts.html

So if we make an object like you said:

   _AddSlots: ( | x = ( | y* = ( | parent* = traits clonable.
                                   sharedNum <- 21.
                               | ).
                          privateNum <- 19.
                      | ).
              | )

First of all, sorry about this very old notation, but if I sent
a picture attached a lot of people wouldn't be able to see it.

   _AddSlots: ( | xc = x copy | ).

Now if we do

   xc sharedNum: 99.
   xc privateNum: 86.

we get

   x sharedNum.  "99 - I said it was shared!"
   x privateNum. "19 - changing the clone had no effect here"

So it works exactly like you thought it would, not like you wanted
it to. You have two options:

  - if you want each clone of "x" to have a separate value for
    "sharedNum", then this might be a strong indication that this
    slot really belongs in "x" and not in its parent

  - if you really need the original structure for some reason while
    still having separate value for the clones, Self can handle that
    as well:

   _AddSlots: ( | x = ( | y* <- ( | parent* = traits clonable.
                                    sharedNum <- 21.
                                | ).
                          privateNum <- 19.
                          copy = ( | newX |
                                     newX: resend.copy.
                                     newX y: y copy.
                                     newX
                                 ).
                      | ).
              | )

Now each clone of "x" will get its own, separate "y" parent object,
and so its own "sharedNum" (making it no longer shared). Note that
for the current Self compilers, this code will be less efficient
than the first one.

-- Jecel



More information about the Self-interest mailing list