Subject: Re: dotimes dolist
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 30 Aug 2000 02:16:01 GMT
Newsgroups: comp.lang.scheme
Message-ID: <8ohqp1$m2hh0$1@fido.engr.sgi.com>
Will Clinger - Sun Microsystems  <william.clinger@east.sun.com> 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)
              `(begin
                 (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)
	    ((2)
	     (bind-list (var ls) parms
	       `(for-each (lambda (,var) ,@body) ,ls)))
	    ((3)
	     (bind-list (var ls result) parms
	       `(begin
		  (for-each (lambda (,var) ,@body) ,ls)
		  ,result)))
	    (else
	      (error "bad dolist args" parms))))

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


-Rob

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