unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Andy Wingo <wingo@pobox.com>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: reload-module
Date: Fri, 19 Nov 2010 16:45:32 +0100	[thread overview]
Message-ID: <m3pqu12u77.fsf@unquote.localdomain> (raw)
In-Reply-To: <87y68qxq4q.fsf@gnu.org> ("Ludovic Courtès"'s message of "Thu, 18 Nov 2010 22:45:25 +0100")

On Thu 18 Nov 2010 22:45, ludo@gnu.org (Ludovic Courtès) writes:

> Hello!
>
> "Andy Wingo" <wingo@pobox.com> writes:
>
>> +(define (reload-module m)
>> +  (let ((f (module-filename m)))
>> +    (if f
>> +        (save-module-excursion
>> +         (lambda () 
>> +           ;; Re-set the initial environment, as in try-module-autoload.
>> +           (set-current-module (make-fresh-user-module))
>> +           (primitive-load-path f)
>> +           m))
>> +        ;; Though we could guess, we *should* know it.
>> +        (error "unknown file name for module" m))))
>
> What about adding
>
>   (module-define-submodule! the-root-module (module-name m)
>                             (let ((x (make-module)))
>                               (set-module-name! x (module-name m))
>                               x))
>
> right before the ‘primitive-load-path’ call, such that the module is
> created anew, instead of being modified incrementally?

That won't work, because it will result in new variables being created
for any new definitions, so old code that had cached the old variables
would no longer do what you expect.

The usual use case is to reload a module "in-place". Not very
functional, no, but some useful things aren't functional :)

Andy
-- 
http://wingolog.org/



  reply	other threads:[~2010-11-19 15:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1821146050.900955.1290113203703.JavaMail.root@zmbs1.inria.fr>
2010-11-18 21:45 ` reload-module Ludovic Courtès
2010-11-19 15:45   ` Andy Wingo [this message]
2010-11-19 22:38     ` reload-module 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=m3pqu12u77.fsf@unquote.localdomain \
    --to=wingo@pobox.com \
    --cc=guile-devel@gnu.org \
    --cc=ludo@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).