* Expanding macros
@ 2012-09-24 21:47 Panicz Maciej Godek
2012-09-26 21:54 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Panicz Maciej Godek @ 2012-09-24 21:47 UTC (permalink / raw)
To: guile-user
Hey,
is there any legitimate way to expand the scheme macros
to the scheme code in guile 2.0?
The macroexpand procedure seems only to compile the code
to the tree-il language (no matter whether 'e, 'c or any other
symbol is passed as a second argument):
(macroexpand '(define (f a b) (list a b)) 'e)
; ===> #<tree-il (define f (lambda ((name . f)) (lambda-case (((a b)
#f #f #f () (a-4236 b-4237)) (apply (toplevel list) (lexical a a-4236)
(lexical b b-4237))))))
thanks
MG
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Expanding macros
2012-09-24 21:47 Expanding macros Panicz Maciej Godek
@ 2012-09-26 21:54 ` Ludovic Courtès
2012-09-28 15:52 ` Panicz Maciej Godek
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2012-09-26 21:54 UTC (permalink / raw)
To: guile-user
Hi,
Panicz Maciej Godek <godek.maciek@gmail.com> skribis:
> is there any legitimate way to expand the scheme macros
> to the scheme code in guile 2.0?
> The macroexpand procedure seems only to compile the code
> to the tree-il language (no matter whether 'e, 'c or any other
> symbol is passed as a second argument):
>
> (macroexpand '(define (f a b) (list a b)) 'e)
> ; ===> #<tree-il (define f (lambda ((name . f)) (lambda-case (((a b)
> #f #f #f () (a-4236 b-4237)) (apply (toplevel list) (lexical a a-4236)
> (lexical b b-4237))))))
There’s the ,expand command at the REPL.
It’s implemented like this:
(define (repl-expand repl form)
(let ((from (repl-language repl))
(opts (repl-compile-options repl)))
(decompile (compile form #:from from #:to 'tree-il #:opts opts
#:env (current-module))
#:from 'tree-il #:to from)))
Psyntax, the macro expander, returns tree-il, hence the need to go
through ‘decompile’.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Expanding macros
2012-09-26 21:54 ` Ludovic Courtès
@ 2012-09-28 15:52 ` Panicz Maciej Godek
2012-10-02 14:04 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Panicz Maciej Godek @ 2012-09-28 15:52 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
Bonjour,
> There’s the ,expand command at the REPL.
>
> It’s implemented like this:
>
> (define (repl-expand repl form)
> (let ((from (repl-language repl))
> (opts (repl-compile-options repl)))
> (decompile (compile form #:from from #:to 'tree-il #:opts opts
> #:env (current-module))
> #:from 'tree-il #:to from)))
>
> Psyntax, the macro expander, returns tree-il, hence the need to go
> through ‘decompile’.
Thanks a lot. By the way, the (undocumented, as of 2.0.5) decompile
function returns two values -- the first being the expanded expression
and the second -- #f.
As I've figured out from system/base/compile, the second return value
is the environment, but I've been wondering under what circumstances
would that value be different from #f.
Best regards
MG
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Expanding macros
2012-09-28 15:52 ` Panicz Maciej Godek
@ 2012-10-02 14:04 ` Ludovic Courtès
0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2012-10-02 14:04 UTC (permalink / raw)
To: Panicz Maciej Godek; +Cc: guile-user
Hi,
Panicz Maciej Godek <godek.maciek@gmail.com> skribis:
> By the way, the (undocumented, as of 2.0.5) decompile
> function returns two values -- the first being the expanded expression
> and the second -- #f.
> As I've figured out from system/base/compile, the second return value
> is the environment, but I've been wondering under what circumstances
> would that value be different from #f.
AFAICS it’s currently unused.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-10-02 14:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-24 21:47 Expanding macros Panicz Maciej Godek
2012-09-26 21:54 ` Ludovic Courtès
2012-09-28 15:52 ` Panicz Maciej Godek
2012-10-02 14:04 ` Ludovic Courtès
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).