unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos via General Guile related discussions <guile-user@gnu.org>
To: Vivien Kraus <vivien@planete-kraus.eu>,
	 "guile-user@gnu.org" <guile-user@gnu.org>
Subject: RE: Dynamically add bindings to the module currently being compiled
Date: Sat, 9 Nov 2024 14:06:45 +0100	[thread overview]
Message-ID: <20241109140645.ad6k2D00N42S6aw01d6l6y@andre.telenet-ops.be> (raw)
In-Reply-To: <74edf58cb7ea2a86adee326e1083506b0c2dd34c.camel@planete-kraus.eu>

If you dynamically add bindings during _expansion_ (instead of expanding to code that _defines_ and exports something), then naturally the compiler never sees it, so it doesn’t end up in .go and when the .go is loaded, that binding isn’t there anymore.

Proposed alternative:

• Define a mapping of module->collected-strings somewhere.
• Let G_ add things to this mapping, during _expansion_ (syntax-case instead of syntax-rules will be needed).
• Define another macro ‘define-marked-strings’ that, during expansion, looks into this mapping, and from its contents constructs code that defines the variable.

For hygiene, to avoid state and to make it independent of the module system, you could try to make it in the form:

(collect-G-literals marked-strings
  [various definitions])
-> (begin [various definitions] (defined marked-strings '("bla" ...)))

There is something similar to ‘parameterize’ but for macros and syntax that may be useful for this, but I’m not sure if it has the required semantics.

Another option is to forego a macro implementation and instead implement it as a compilation pass. There doesn’t seem to be good support for plugging in custom extra compilation passes, though.

Best regards,
Maxime Devos



  reply	other threads:[~2024-11-09 13:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-09 12:27 Dynamically add bindings to the module currently being compiled Vivien Kraus
2024-11-09 13:06 ` Maxime Devos via General Guile related discussions [this message]
2024-11-09 21:57   ` Vivien Kraus
2024-11-09 22:05     ` Vivien Kraus

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=20241109140645.ad6k2D00N42S6aw01d6l6y@andre.telenet-ops.be \
    --to=guile-user@gnu.org \
    --cc=maximedevos@telenet.be \
    --cc=vivien@planete-kraus.eu \
    /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).