[gambit-list] macro-expand
Christian Jaeger
christian at pflanze.mine.nu
Sat Mar 8 18:10:22 EST 2008
Joel Borggrén-Franck wrote:
> Is there a way to read from pp without
> creating a port first?
>
> (##decompile (lambda (y) (* y y)))
(lambda (y) (* y y))
> (caddr (##decompile (lambda (y) (* y y))))
(* y y)
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:
> (caddr (##decompile (lambda () (begin (form1) (* y y)))))
(form1)
So you want something like:
> (define (macro-expand-decompile-thunk thunk) (let ((code (cddr
(##decompile thunk)))) (if (null? (cdr code)) (car code) `(begin , at code))))
> (macro-expand-decompile-thunk (lambda () (* y y)))
(* y y)
> (macro-expand-decompile-thunk (lambda () (begin (form1) (* y y))))
(begin (form1) (* y y))
> I played around with with-output-to-string
> first but that just gave me a headache.
pp doesn't print to current-output-port by default.
> (with-output-to-string "" (lambda () (pp "fun")))
"fun"
""
> (with-output-to-string "" (lambda () (pp "fun" (current-output-port))))
"\"fun\"\n"
Christian.
More information about the Gambit-list
mailing list