From: David Kastrup <dak@gnu.org>
To: Han-Wen Nienhuys <hanwenn@gmail.com>
Cc: lilypond-devel <lilypond-devel@gnu.org>,
Guile Devel <guile-devel@gnu.org>
Subject: Re: definitions in macros?
Date: Sun, 22 Mar 2020 22:09:25 +0100 [thread overview]
Message-ID: <87v9mw9jwa.fsf@fencepost.gnu.org> (raw)
In-Reply-To: <CAOw_e7bVfgmrMf-ZtjF4zJqESLS1Y6CbHNztxcvfiEYwX5PzwQ@mail.gmail.com> (Han-Wen Nienhuys's message of "Sun, 22 Mar 2020 20:07:11 +0100")
Han-Wen Nienhuys <hanwenn@gmail.com> writes:
> Hi there,
>
> in my quest to get lilypond working with GUILE 2+, I've hit another
> stumbling block.
>
> In order to make compilation with GUILE 2+ working, we have to move
> away from runtime symbol definition (ie. module-define! calls).
>
> In the code below, it looks like only one of the two definitions in
> the body of my-macro-new takes effect. Is this expected, and if so,
> why?
>
> (defmacro-public my-macro-old (command-and-args . definition)
> (module-define! (current-module) 'x1 "I am X1\n")
> (module-define! (current-module) 'x2 "I am X2\n"))
>
> (defmacro-public my-macro-new (command-and-args . definition)
> `(define p "i am P\n")
> `(define q "i am Q\n"))
This is very much expected. The macro body contains two side-effect
free expressions (namely quoted lists) and returns the last one which is
(define q "i am Q\n")
This then gets evaluated at run time, defining q .
You probably wanted something like
`(begin (define p ...) (define q ...))
as your body (and return expression) instead.
> (my-macro-old 1 2)
> (my-macro-new 1 2)
> (display x1)
> (display x2)
> (display q)
> (display p)
>
>
> thanks,
--
David Kastrup
next prev parent reply other threads:[~2020-03-22 21:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 19:07 definitions in macros? Han-Wen Nienhuys
2020-03-22 19:16 ` Matt Wette
2020-03-22 21:09 ` David Kastrup [this message]
2020-03-23 7:21 ` Han-Wen Nienhuys
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=87v9mw9jwa.fsf@fencepost.gnu.org \
--to=dak@gnu.org \
--cc=guile-devel@gnu.org \
--cc=hanwenn@gmail.com \
--cc=lilypond-devel@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).