[gambit-list] macro-expand

Christian Jaeger christian at pflanze.mine.nu
Sat Mar 8 18:37:54 EST 2008


I 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:
>   

I forgot that the macro could also have output nothing, i.e. (begin). 
This should be correct in all(tm) circumstances:

(define (macro-expand-decompile-thunk thunk+)
  (let* ((code (cddr (##decompile thunk+)))
     (len (length code))
     ;; strip last faked element:
     (code (take code (- len 1))))
    (cond
     ((null? code)
      '(begin))
     ((null? (cdr code))
      (car code))
     (else
      `(begin , at code)))))

(define-macro (macro-expand syntax)
  `(cj-macro-util#macro-expand-decompile-thunk (lambda () ,syntax 
(fake-form))))

It requires the srfi-1 take function and expects that this code is put 
into the cj-macro-util# namespace.

Christian.




More information about the Gambit-list mailing list