[plt-scheme] Macro Problem

From: Bill Wood (wtwjek at winternet.com)
Date: Wed Mar 26 14:01:33 EST 2003

I'm trying to build a macro for an imperative control construct similar
to "do"
The construct's shape and its intended expansion is

  ;;; (dgdo ((V1 E1)              (letrec
  ;;;         . . .                 ((loop
  ;;;        (Vm Em))                  (lambda (V1 .. Vm)
  ;;;       (E1 .. Ep)      ==>          (cond (C1 E11 .. E1k1 (loop V1
.. Vm))
  ;;;   (C1 E11 .. E1k1)                            . . .
  ;;;        . . .                             (Cn En1 .. Enkn (loop V1
.. Vm))
  ;;;   (Cn En1 .. Enkn))                      (else (begin E1 ..
Ep))))))
  ;;;                               (loop E1 ...
Ep))                          

Just FYI, the first form after "dgdo" is a list of pair-lists
establishing the
usual local binding environment, The second form is a list containing a
sequence of expressions to be evaluated upon termination, and forms 3
through
n comprise a set of guarded expression sequences, similar to the body of
a
"cond".  The idea is to repeatedly evaluate that "cond" body until all
the
guards are false, at which time the termination expression sequence is
executed
and the "dgdo" returns its value.  This amounts to an implementation of
Dijkstra's
"guarded do" command.

The code I wrote is

  (define-syntax dgdo (syntax-rules ()
  		        ((dgdo ((var val) ...)
                               (final ...)
                           (test exp ...) ...)
  		         (letrec
			   ((loop
			      (lambda (var ...)
			        (cond (test exp ... (loop var ...))
                                      ...
				      (else (begin final ...))))))
			   (loop val ...)))))

When I load this into mzscheme (version 200) I get

  guarded-dos.scm:31:51: syntax: too many ellipses in template at:
  (loop var ...) in: (letrec ((loop (lambda (var ...)
   (cond (test exp ... (loop var ...)) ... (else (begin final ...))...

I cook-booked this as much as I could from the derived forms
in sec. 8.3 of the R5RS report.  This was pretty easy using
Common Lisp "defmacro", so it's obvious my lack of understanding
of the syntax-rules mechanism is the culprit.

Can anyone assist me?

Thanks,

 -- Bill Wood
    bill.wood at acm.org


Posted on the users mailing list.