guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: reload-module


From: Andy Wingo
Subject: Re: reload-module
Date: Fri, 19 Nov 2010 16:45:32 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

On Thu 18 Nov 2010 22:45, address@hidden (Ludovic Courtès) writes:

> Hello!
>
> "Andy Wingo" <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]