viewpoint programming (was: super super)

Jecel Assumpcao Jr. jecel at merlintec.com
Wed Feb 16 22:46:28 UTC 2000


Yoshiki Ohshima wrote:
> Andreas Raab wrote:
> > I was always wondering why there is no real equivalent to
> > this in any OOP system I've seen so far.
> 
>   double-colon in C++.

Very close, and exactly it for his particular examples. In Self it is possible
to write:

        someObject _Perform: '=' DelegatingTo: object With: anotherObject
and
        aDictionary _Perform: 'do:' DelegatingTo: set With: aBlock

but it is so ugly I am sure nobody would actually do it.

In NeoLogo, I often found myself needing to "go the other way" so I came up
with the "as" method. Objects in NeoLogo are just lists of names and values
(what is called an association list in Lisp) so you could do something like
this (not really, but it makes the illustration simpler):

    make "a  [ x 3 y 4 ]

a normal 2D point...

    make "b sentence [ z 9 ]

nothing much...

    make "c sentence :b copy :a

a 3D point. The way sentence is defined, the copy message to b is not needed.
The colons aren't needed either, but writing it like this makes it more
Logo-like.

We shall say that the "c" object *includes* the "a" object. The expression

            c as a

will simply return "a" since that is how "c" looks from the "a" viewpoint.
Strangely enough

            a as c

will return "c". That is because the "c" object itself includes "a", so it is a
good viewpoint (refinement) for "a". If we tried

            a as b

we would also get "c" as an answer. That is because though "b" doesn't include
"a" itself, one of its clones ("c" in this case) does so we suppose that this
clone is a good viewpoint for "a". Just one more strange object

    make "d [ name 'John Wayne']

so that when we try

            a as d

the best the system can do is to create a new object and return that:

            sentence :d copy :a

which I am hoping makes at least some sense. It might have been better to
return an error in this case. Also, it might be interesting to have
"asExisting" which would work in the first two cases but return an error in the
third, and "asNew" which would make a clone in all cases.

This seemed to me to be an interesting direction to follow, but there would
need to be a way to preserve the original viewpoint. Otherwise

          (someObject as object) = anotherObject
and
          (aDictionary as set) do aBlock

wouldn't work as not only the lookup of the #= and #do: messages would be
affected but also all lookups in the resulting methods as well (the meaning of
<self> has changed). That isn't what "super" does. Besides, "as" can be a very
expensive operation.

-- Jecel





More information about the Squeak-dev mailing list