This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Philosophy and object systems (was Re: goops/guile doc)


Michael Vanier <mvanier@bbb.caltech.edu> writes:

> On a separate topic: even though CLOS-style generic functions can
> indeed emulate single-dispatch object systems, my understanding is
> that the resulting system will still not have encapsulation.  Most
> CLOS advocates seem to feel that encapsulation isn't worth anything.
> This is a legitimate philosophical view.  The more interesting
> question is: can a CLOS-like system emulate single-dispatch OO
> systems all the way, including encapsulation?  If you want/need to
> use a module/package system on top of CLOS to achieve this, go right
> ahead :-) This is not just academic; guile is supposed to be able to
> mimic other scripting languages, and at least some of them support
> private variables in their OO systems (e.g. python).

You could have a package for each class, with accessors available in
that class only.  Perhaps wrapping around the defclass macro to define
new modules/packages with each class and if there are "freinds" then
you have the new module import the modules it is freinds with.  You
could still use direct slot-value access to get around this if you
know the slot-names. 

I don't know what the slot access protocol looks like in GOOPS, but in
CLOS you could perhaps define a method for slot-value-using-class
which looks at a lexically scoped *self* or something to determine
what "class" we are in at the present time.  If we are not a freind of
the class being accessed, or the class itself, then we can throw an
error.  Then method definition would wrap a unwind-protect binding
*self* to the current class around the user supplied method body.

Method dispatch would occur at runtime using the type of the values in
question, which may have different results than static dispatch based
on variable type(like Java does, at least from my understanding of it
while attempting to mimic in in Kawa).

I would not know the specifics of doing this in GOOPS with the guile
module system, as I'm not very familiar with them.  I am quite certain
that it is doable in GOOPS.  I prefer delaying decisions as long as
possible and letting the user decide what is wrong and what is right,
one of the reasons I like CLOS.  This could be because I quite
honestly hate coding, as opposed to programming.

-- 
Craig Brozefsky                      <craig@red-bean.com>
Free Scheme/Lisp Software  http://www.red-bean.com/~craig
"Hiding like thieves in the night from life, illusions of 
oasis making you look twice.   -- Mos Def and Talib Kweli

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]