* reload-module [not found] <1821146050.900955.1290113203703.JavaMail.root@zmbs1.inria.fr> @ 2010-11-18 21:45 ` Ludovic Courtès 2010-11-19 15:45 ` reload-module Andy Wingo 0 siblings, 1 reply; 3+ messages in thread From: Ludovic Courtès @ 2010-11-18 21:45 UTC (permalink / raw) To: Andy Wingo; +Cc: guile-devel 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? Thanks, Ludo’. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: reload-module 2010-11-18 21:45 ` reload-module Ludovic Courtès @ 2010-11-19 15:45 ` Andy Wingo 2010-11-19 22:38 ` reload-module Ludovic Courtès 0 siblings, 1 reply; 3+ messages in thread From: Andy Wingo @ 2010-11-19 15:45 UTC (permalink / raw) To: Ludovic Courtès; +Cc: guile-devel 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/ ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: reload-module 2010-11-19 15:45 ` reload-module Andy Wingo @ 2010-11-19 22:38 ` Ludovic Courtès 0 siblings, 0 replies; 3+ messages in thread From: Ludovic Courtès @ 2010-11-19 22:38 UTC (permalink / raw) To: guile-devel Hello, Andy Wingo <wingo@pobox.com> writes: > 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. Hmm, right; ditto for those that have cached the module itself. Oh well... Thanks, Ludo’. ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-11-19 22:38 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [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 ` reload-module Andy Wingo 2010-11-19 22:38 ` reload-module Ludovic Courtès
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).