Expansion problem

Jean-Michel HUFFLEN <jmhuffle-qPpMuP/[email protected]>
Newsgroups gmane.comp.lang.racket.user,gmane.lisp.scheme.plt
Message-ID <[email protected]>
    Hello, Racket's friends!

    I'm trying to define the "do*" special form of Common Lisp by a  
Racket macro. Let us recall that "do*" is analogous to "do", but the  
bindings and updating of variables are done sequentially. A simple  
example where "do" and "do*" do not yield the same result could be:

(do* ((i 0 (+ i 1))
       (j 0 (+ i j 1)))
      ((= i 10) (+ i j))
   (write (cons i j))
   (newline))

    In addition, I allow bindings like (var init step) and (var init),  
processed like (var init var). If I define "do*" as follows:

(define-syntax do*
   (syntax-rules ()
     ((do* ((var init step ...) ...) (test expr-0 ...) body-expr-0 ...)
      (let* ((var init) ...)
        (let loop ()
          (if test
	     (do* "ending" expr-0 ...)
              (begin
                body-expr-0 ... (do* "step" var step ...) ... (loop))))))
     ((do* "ending") (if #f #f))
     ((do* "ending" expr-0) expr-0)
     ((do* "ending" expr-0 ...) (begin expr-0 ...))
     ((do* "step" var) #f)
     ((do* "step" var step) (set! var step))))

that works, but I don't like this solution because of side effects. If I try:

(define-syntax do*
   (syntax-rules ()
     ((do* ((var init step ...) ...) (test expr-0 ...) body-expr-0 ...)
      (let* ((var init) ...)
        (let loop ((var var) ...)
	 (if test
	     (do* "ending" expr-0 ...)
	     (begin
	       body-expr-0 ...
                (let* ((do* "step" var step ...) ...) (loop var ...)))))))
     ((do* "ending") (if #f #f))
     ((do* "ending" expr-0) expr-0)
     ((do* "ending" expr-0 ...) (begin expr-0 ...))
     ((do* "step" var) (var var))
     ((do* "step" var step) (var step))))

that results in the following error:

let*: bad syntax (not an identifier and expression for a binding) in:  
(do* "step" i (+ i 1))

    Please, does it mean that the bindings of a "let*" special form  
cannot be the result of a macro expansion? Many thanks in advance,

J.-M. Hufflen


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

-- 
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.