[plt-scheme] Swindle CLOS ?
On Mar 9, Kyle Smith wrote:
> 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$,1ry(Bs 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 $,1rx(Bwhite))
> (set-ColoredPoint-x! thePoint 5)
> (set-ColoredPoint-y! thePoint 6)
> (set-ColoredPoint-color! thePoint $,1rx(Bblack)
> (printf $,1r|(B~n=>~a ~a ~a$,1r}(B (ColoredPoint-x thePoint) (ColoredPoint-y thePoint)
> (ColoredPoint-color thePoint))
> =>5 6 black
>
> Note: no Point accessors were required to manipulate the inherited
> fields, `x$,1ry(B and `y$,1ry(B from within the ColoredPoint class. ColoredPoint
> has accessors of its own for these fields.
I don't see any reason to do this: conceptually, `x' is a field of
Point, so a `ColoredPoint-x' doesn't make much sense to me. But the
`Point-x' thing is in any case a generic function -- which means that
it does not "belong" to Point -- it just happens to have a method that
is qualified for Points. So, you can have it called `get-x' and then
it's independent of any class name (there is an option that makes it
use `x' for a name, it's just that it's a bad name in this case).
(There is even a customization option that defines the accessor as a
plain function instead of a generic -- basically one that is doing the
actual accessing through (slot-ref foo 'x).)
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!