[plt-scheme] Swindle

From: Eli Barzilay (eli at barzilay.org)
Date: Wed Apr 28 21:33:00 EDT 2004

On Apr 28, Paulo Jorge de Oliveira Cantante de Matos wrote:
> Hi all,
> 
> I'm trying to use swindle. I hope it is not too off topic.

[No.  The only reason it is not merged into the plt tree is laz^H^H^H
lack of time.]


> I know clos from programming some projects in CMUCL clos, based on
> "Object Oriented Programming in Common Lisp" by Sonya Keene.  The
> first thing I tried was to run a simple clos file in swindle which
> bummm, well... as you can imagine I had some problems.

Swindle shares the same principles, and almost of of the functionality
of CLOS, but it still Scheme, with Scheme syntax despite some things
that makes it look a bit like CL.


> I've seen the documentation (or better yet, the reference) of
> swindle online, however didn't help much. Is there any tutorial,
> examples with it, or something that can help me point out the
> differences and get started?

No.  The only thing is that documentation (which you can also find in
the doc.txt file).


> Another very important question, I have the possibility for college
> to implement a planner in CMUCL Clos, or in swindle. Is swindle
> stable enough so that it doesn't bring me problems while developing
> the planner?

It is very stable.  No major changes for a few years now.  One major
factor in your decision should be speed: if you really need it, then
CMUCL is probably a better choice.  On the other hand, Swindle will
give you a better language to work with (IMO. Don't quote me on
c.l.l), better environment, and better libraries -- all plt-scheme
modules are available without any change to your code or to the
library code, even when the library code uses a different object
system.


> Oh, if you wish to know, what I tried in swindle was:
> 
> (defclass fol-formula ()
>     ()))
> 
> (defclass fol-connective (fol-formula)
>   ((arg1 :accessor connective-arg1 :initarg :arg1)
>    (arg2 :accessor connective-arg2 :initarg :arg2)))
> 
> (defmethod print-object ((c fol-connective) stream)
>   (format stream "#<Connective ~A ~A>"
>           (connective-arg1 c)
>           (connective-arg2 c)))

You have an extra pair of parens around the slots.  This is how you
would do it:

  (defclass <formula> ())
  
  (defclass <connective> (<formula>)
    (arg1 :accessor connective-arg1 :initarg :arg1)
    (arg2 :accessor connective-arg2 :initarg :arg2))
  
  (defmethod (print-object (c <connective>) escape stream)
    (fprintf stream "#<Connective ~a ~a>"
             (connective-arg1 c)
             (connective-arg2 c)))

and given this, (make <connective> :arg1 "foo" :arg2 "bar") would
print what you'd expect it to.

Notes:

1. Swindle follows Scheme and does not invent another namespace for
   classes, instead, they are normal bindings.  Because of this, I
   usually use <foo> for class names.
   [This makes cute things like:
     (defmethod (foo (x (car <number> <string>))) ...)
   work as expected (the class parts of the form is evaluated as
   usual).]

2. Since you're still in PLT Scheme, there is no need for a `fol-'
   prefix for everything you do, just put it all in a module.

3. A defmethod form can use the Lisp-like form:
     (defmethod name (args ...) body ...)
   but it is much better to use the more Schemely form:
     (defmethod (name args ...) body ...)

4. PLT Scheme has `fprintf' as a limited version of CL's `format'.
   Swindle adds `echo' which supports part of the power you get with
   CL's format.

5. Note the arguments for the `print-object' generic function.

6. Worth repeating: Swindle is a [PLT] Scheme library, it uses Scheme
   constructs and syntax.  It has some design decisions that are more
   in the spirit for Scheme than some of the ugly (mostly macro-
   hacked) corners of CLOS.  It comes with some libraries that will
   make life easier for a CL programmer, but it is *not* a syntactic-
   level compatibility layer for CL.

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.