simple object model
Jecel Assumpcao Jr
jecel at merlintec.com
Mon Apr 16 23:34:10 UTC 2001
I am still thinking about a simple object model. I am working at a low
level, like the C++ structures in Self 4.1.2, and not a high level
language object model like in Self or Smalltalk. The idea is to be able
to build these high level models using what I am proposing and the
application programmer wouldn't have to be aware of this.
Another detail is that the simple text representation I will use in
this email is obviously missing a lots of stuff (I will only use simple
literal values instead of complex expressions) but that is ok since it
is supposed to be created by tools instead of directly typed in.
An object has three parts:
( <indexed values> | <named values> | <helper objects> )
These will be explained below, but I should first mention that any of
these parts can be missing. A very simple vector object, for example,
might have nothing but the indexed values:
( 1 1 2 3 5 8 13 21 | | )
is a vector with 8 indexed values, accessed with indexes 0 through 7.
The trailing "|" separators can be omitted in cases like this:
( 1 1 2 3 5 8 13 21 )
is exactly the same object.
The "helper objects" supply the names for the "named values" in their
indexed values section - here is the classic 2d point:
( | 3 4 | ( 'x' 'y' ) )
It has one helper object that is a simple 2 element vector. The point
itself doesn't have any indexed values, and the name of the first named
value (3) is taken from the first indexed value of the helper object
('x'). The helper objects can be more complex than this, however:
( | 3 4 | ( 'x' 'y' | 3.14 <some code> | ( 'pi' '+' ) ) )
Too much like Lisp? :-) Sorry - a drawing would be much more
understandable. Aligning the indexed values of the helper objects with
the named values of the "main" object also helps a little:
( | 3 4 |
( 'x' 'y' | 3.14 <some code> |
( 'pi' '+'
Still very much like Lisp.... and it would be much more complicated if
I showed what <some code> was really like.
Anyway, the whole point is that the look up algorithm recurses into the
helper objects when looking for a name, so that the point in the
example can understand the messages 'x', 'y', 'pi' and '+'. In this
simple model everything is made of the same kind of stuff, yet it can
be used to emulate Self, the various Smalltalks, NewtonScript and
probably other interesting languages as well.
This is simple enough that small implementations can be created, though
I am more interested in high performance ones.
One more example - if there are no helper objects but the object does
have named values, then it is used as its own helper object:
( 'x' 'y' | 3 4 )
So very simple objects can be self describing. The advantage of the
first point example is that it only takes up 3 words when cloned, while
this one takes up 4. I said this was a low level thing.
More information about the Self-interest