unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: Andy Wingo <wingo@igalia.com>
Cc: Guile Devel <guile-devel@gnu.org>
Subject: Mutating public bindings of a declarative module
Date: Sun, 24 Nov 2019 18:54:25 +0100	[thread overview]
Message-ID: <87a78lyxbi.fsf@gnu.org> (raw)

Hello!

It seems that if you ‘set!’ a public variable of a declarative module,
the change is visible to all the module users, but it’s not necessarily
visible to procedures within that module, presumably because they use an
inlined or specialized variant of that thing.

I would have imagined that public bindings are considered mutable and
thus not subject to inlining; OTOH, that would obviously be a loss, so
the current approach makes sense.

Anyway, it complicates a use case for me.  In Guix, we “mock” bindings
like so:

  (define-syntax-rule (mock (module proc replacement) body ...)
    "Within BODY, replace the definition of PROC from MODULE with the definition
  given by REPLACEMENT."
    (let* ((m (resolve-interface 'module))
           (original (module-ref m 'proc)))
      (dynamic-wind
        (lambda () (module-set! m 'proc replacement))
        (lambda () body ...)
        (lambda () (module-set! m 'proc original)))))

and that allows us to write tests that temporarily modify public (or
private!) bindings.

It seems like this could be addressed by compiling selected modules with
‘user-modules-declarative?’ set to #false, or by avoiding the above hack
altogether when possible, but I thought I’d share my impressions and
listen to what people think.  :-)

Thanks,
Ludo’.



             reply	other threads:[~2019-11-24 17:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-24 17:54 Ludovic Courtès [this message]
2019-11-25  6:23 ` Mutating public bindings of a declarative module Amirouche Boubekki
2019-11-25  8:33 ` Andy Wingo
2019-11-25 21:51   ` 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=87a78lyxbi.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@gnu.org \
    --cc=wingo@igalia.com \
    /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).