[comp.lang.scheme] How to implement OOP member variables?

andrew@astro.psu.edu (Andrew Wilcox) (02/28/91)

I'm interested in writing a simulator.  What I would like to have is a
group of objects running concurrently, that communicate by sending
messages to each other asynchronously.  (I recently learned there was
a name for this: "object-oriented concurrent programming".)

I'd like your thoughts on writing an oocp library in Scheme.  (Or
should I use another language instead?)  I've written a process
manager / task switcher using continuations.  (This was a real
pleasure; my first exposure to the continuation abstraction.)  Now I'm
thinking about how to implement member variables in the object
methods.

A straightforward implementation would be to have each method
represented by a function that was passed a reference to the object's
variables in a value list.

The value list could be an association list of symbols representing
member variables in the class and their values, plus value lists for
each superclass of the object.

   value-list :=  (alist-of-variables (value-list-of-superclass1 ...))

Putting the values in a tree structure means that when a superclass's
method was called, the member variables that the superclass knows
about could be easily extracted.

The method function would call a function like
(ref-var my-value-list 'y-coord), which would search the value list
for the variable.  Naturally the form could be make prettier with a macro.

Ok, so is this how you would do it?  I've looked at Scoops, and I
don't understand what it's doing.  It seems to be changing the
environment for the method when a message is sent.  (Am I right?)  The
MIT Scheme manual warns that accessing the environment is inefficient,
but is it more inefficient than searching association lists for each
variable reference?

Thanks,

Andrew Wilcox
Department of Astronomy & Astrophysics, Pennsylvania State University
(andrew@astro.psu.edu)