On Mon, Mar 10, 2008 at 3:03 PM, Joel Borggrén-Franck joel.borggren.franck@gmail.com wrote:
On Sun, Mar 9, 2008 at 12:10 AM, Christian Jaeger christian@pflanze.mine.nu wrote:
BTW be careful: macros using (begin ..) to output multiple forms will not give what you want since the current interpreter strips the begin during parsing time:
Thx for the heads up.
First i tried:
(define-macro (macro-expand mac) (let ((port (gensym)) (form (gensym)) (code (gensym))) `(let ((,port (open-string))) (pp (lambda () ,mac) ,port) (let* ((,form (read ,port)) (,code (cddr ,form))) (cond ((null? ,code) '(begin)) ((null? (cdr ,code)) (car ,code)) (else `(begin ,@,code)))))))
It works well. Then I decided to put it all in a let* since it was only a single expression between the two lets. Wasteful (one unnecessary (gensym), one extra nested let) or good looking?
;; Expand gambit-c macro form. (define-macro (macro-expand-dummy mac) (let ((port (gensym)) (dummy (gensym)) (form (gensym)) (code (gensym))) `(let* ((,port (open-string)) (,dummy (pp (lambda () ,mac) ,port)) (,form (read ,port)) (,code (cddr ,form))) (cond ((null? ,code) '(begin)) ((null? (cdr ,code)) (car ,code)) (else `(begin ,@,code))))))
/Joel