Subject: Re: dotimes dolist
From: (Rob Warnock)
Date: 30 Aug 2000 02:16:01 GMT
Newsgroups: comp.lang.scheme
Message-ID: <8ohqp1$m2hh0$>
Will Clinger - Sun Microsystems  <> wrote:
| Rob Warnock posted some macros that, in order to understand,
| I translated into R5RS Scheme...

Thanks!! I confess that since I switch back & forth between Scheme & CL
a good bit, I've personally been somewhat lazy about simply using "defmacro"
in both environments.

| so I might as well share my translations, warning that this code hasn't
| really been tested.  (The "?IGNORED ..." in the first definition is for
| compatibility with Warnock's version.  You will obtain better syntax
| checking if you delete it.)

As you should. My use of "(var ls . result)" instead of checking explicitly
for exactly one of "(var ls)" or "(var ls result)" doesn't really correspond
to CL syntax, but was again laziness on my part. Instead of this:

        (defmacro dolist (parms . body)
          (bind-list (var ls . result) parms
            (if (null? result)
              `(for-each (lambda (,var) ,@body) ,ls)
                 (for-each (lambda (,var) ,@body) ,ls)
                 ,(car result)))))

I suppose I probably should have written something like this:

        (defmacro dolist (parms . body)
	  (case (length parms)
	     (bind-list (var ls) parms
	       `(for-each (lambda (,var) ,@body) ,ls)))
	     (bind-list (var ls result) parms
		  (for-each (lambda (,var) ,@body) ,ls)
	      (error "bad dolist args" parms))))

or even better, used "case-lambda" (though that's not all that widely
available either).


Rob Warnock, 41L-955
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		PP-ASEL-IA
Mountain View, CA  94043