just methods (was: Issues about delegation)

Jecel Assumpcao Jr jecel at merlintec.com
Thu Nov 6 23:21:34 UTC 2003


On Thursday 06 November 2003 18:58, J. Baltasar GarcĂ­a Perez-Schofield 
wrote:
> >It complicates everything. So let's just have methods instead.
>
>          Are you serious ?

Partly.

>          I mean, would you really suggest for an object-oriented
> language objects WITHOUT attributes ?
>          Is this feasible ?

It has been done. The Dinnerbell language at Sony, for example. It used 
pattern matching to fetch messages from its queue. So if an object had 
a

               x: 3

message pending, then some pattern like

              x: v ==> ....

would retrieve it. Here is (not with their actual syntax) the kind of 
thing you could do:

           inc: i ; x: v  ==> self x: (v+i)

so if the object had both a "x:3" and a "inc: 5" pending, these two 
messages would be removed from the queue and a new "x: 8" message would 
be added to it.

There are interesting advantages to this approach, but I don't seriously 
recommend it for general use. As Dave said in his talk, the idea of 
state is common enough that we should make use of it.

>          Can I use a method to hold a value ? I think I can use a
> method to hold a constant value ...

Exactly.

>          I think it's feasible to create a syntax in which methods
> and attributes are managed the same way (you don't know whether
> you're calling a method to get a reference to an object o just
> accesing an attribute) ... but ...

You are describing Self, here. In my implementation (now called Neo 
Smalltalk), if you have an object like

     (|  var <- 2.
         const = 42.
         meth = (var+const)
     |)

you would get the following assembly language (yes, that is the syntax I 
use for it!) code

     "var"
         state read: 1 in: _.
         end retNear: _.
     "var:"
         state write: 1 in: _ with: _.
         end retNear: _.
     "const"
         indirect push: 42.
         end retNear: _.
     "meth"
         context new.
         context grabArg.  "self"
         frame read: 5.
         indirect send: 'const' to: _.
         frame read: 5.
         indirect send: 'var' to: _.
         indirect send: '+' to: _.
         end retNear: _.

and the object would have the value "2" in word 1. The "_" means the top 
of the stack. You could also write var as

    end retNear: (state read: 1 in: _).

I have eliminated the "send to implicit self" instruction from the 
hardware, so "meth" is a bit longer than it could have been.

Regular Self is pretty much like this too, but since the data and 
constant slots use flags instead of code to represent their 
functionality I thought this example would show better how close to 
"only behavior" we can get in a practical system.

-- Jecel
p.s.: all the instructions are listed in 
http://www.merlintec.com:8080/software/3



More information about the Self-interest mailing list