add `reload-module' to boot-9
authorAndy Wingo <wingo@pobox.com>
Thu, 18 Nov 2010 20:48:55 +0000 (21:48 +0100)
committerAndy Wingo <wingo@pobox.com>
Thu, 18 Nov 2010 20:48:55 +0000 (21:48 +0100)
* module/ice-9/boot-9.scm (reload-module): New procedure,
  programmatically reloads the source file corresponding to the given
  module.

module/ice-9/boot-9.scm

index b3b6893..24ce621 100644 (file)
@@ -2252,6 +2252,18 @@ If there is no handler at all, Guile prints an error and then exits."
 (define (try-load-module name version)
   (try-module-autoload name version))
 
+(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))))
+
 (define (purify-module! module)
   "Removes bindings in MODULE which are inherited from the (guile) module."
   (let ((use-list (module-uses module)))