[plt-scheme] Help with a macro

From: Evan Farrer (farrer at cs.utah.edu)
Date: Mon Oct 3 09:40:47 EDT 2005

I've run into a problem with a macro that I'm writing.  I've come up with a simple example that demonstrates the behavior that I'm seeing.

(define-syntax (a-loop stx)
  (syntax-case stx (for)
               [(_ count body ...)
               (with-syntax ([itid (datum->syntax-object (syntax count) 'it)])     
                            (let ([done (equal? 0 (syntax-object->datum #'count))]
                                        [next (sub1 (syntax-object->datum #'count))])
                              #`(let ([itid count])
                                  #,(if done
                                      #'(begin body ...)
                                      #`(begin
                                          body ...
                                          (_ #,next body ...))))))]))

If I call the following like:
  (a-loop 9 (printf "~a" it))

I get a series of 9's  I'd expect "9876543210".  I've tried running it under the expander language and from what I can see, everything should be working.  Can anyone enlighten me as to where my thinking is wrong, and how this should be implemented?

Thanks,

Evan


Posted on the users mailing list.