[plt-scheme] Swindle CLOS ?

From: Kyle Smith (airfoil at bellsouth.net)
Date: Fri Mar 9 14:24:59 EST 2007

I'm currently converting the object system called Meroonet used in 
Christian Queinnec's "Lisp In Small Pieces" to Swindle CLOS.  Everything 
was proceeding more or less smoothly until I ran up against a 
fundamental difference in the way ancestor field accessors are treated 
by the two systems.  Meroonet takes the position that a class B derived 
from class A inherits the accessors from class A. Where as Swindle CLOS 
does not. This means, that in Swindle, for a class B object to access 
the slots inherited from class A it needs to call them using class A’s 
accessors. For example in Meroonet it is legal to say:

_*Meroonet*_
(define class Point Object (x y))
(define class ColoredPoint Point (color))
(define thePoint (make-ColoredPoint :x 3 :y 44 :color ‘white))
(set-ColoredPoint-x! thePoint 5)
(set-ColoredPoint-y! thePoint 6)
(set-ColoredPoint-color! thePoint ‘black)
(printf “~n=>~a ~a ~a” (ColoredPoint-x thePoint) (ColoredPoint-y thePoint)
(ColoredPoint-color thePoint))
=>5 6 black

Note: no Point accessors were required to manipulate the inherited 
fields, `x’ and `y’
from within the ColoredPoint class. ColoredPoint has accessors of its 
own for these
fields.

Whereas in Swindle it needs to written as:
_*Swindle CLOS
*_(defclass Point (Object) x y :auto #t :print #t)
(defclass ColoredPoint (Point) color :auto #t :print #t)
(define thePoint (make-ColoredPoint :x 3 :y 44 :color ‘white))
(set-Point-x! thePoint 5)
(set-Point-y! thePoint 6)
(set-aColoredPoint-color! thePoint ‘black)
(printf “~n=>~a ~a ~a” (Point-x thePoint) (Point-y thePoint) 
(ColoredPoint-color
thePoint))
=>5 6 black

It is not a big deal to add, by hand coding accessors for the ancestor 
fields to the derived class.  I've tried it and it works fine.  However, 
to create a true port of Meroonet, where everything is done with macros 
I run into the problems of the scope of these added methods.  The reason 
is that I necessarily have to walk a list of the ancestors and for each 
a list of slots and then create a pair of accessor methods for the 
derived class.  I've yet to figure out how to succeed in walking through 
this list of ancestors and slots without ultimately ending definition 
context when not at top-level, or being forced off top-level, where the 
class was defined.  And so I end up with a class that has top-level 
scope and accessor methods with some form of local scope.

So my question is, am I overlooking some parameter setting of Swindle 
CLOS which would have it behave in the manner of Meroonet regarding 
ancestor accessors?  If not, does someone have a germ of an idea on how 
to execute defmethod statements programmatically without either ending 
definition context or being forced off top-level, without resorting to 
writing the s-expressions out to a file and loading them in?

Thanks,

--kyle

Kyle Smith
airfoil at bellsouth dot net
schemekeys.blogspot.comschemekeys.blogspot.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070309/c12a4a61/attachment.html>

Posted on the users mailing list.