unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: Expanding macros
Date: Wed, 26 Sep 2012 23:54:46 +0200	[thread overview]
Message-ID: <873924phzt.fsf@gnu.org> (raw)
In-Reply-To: CAMFYt2by8UpiparNc4hcL2Ao_c4K+Fo66nMfMH+U3W=CmVTf+A@mail.gmail.com

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’.




  reply	other threads:[~2012-09-26 21:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24 21:47 Expanding macros Panicz Maciej Godek
2012-09-26 21:54 ` Ludovic Courtès [this message]
2012-09-28 15:52   ` Panicz Maciej Godek
2012-10-02 14:04     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873924phzt.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).