(module-make-local-var!): When creating a new variable, initialize it
authorMarius Vollmer <mvo@zagadka.de>
Wed, 22 Dec 2004 14:50:56 +0000 (14:50 +0000)
committerMarius Vollmer <mvo@zagadka.de>
Wed, 22 Dec 2004 14:50:56 +0000 (14:50 +0000)
to the value of any imported variable with the given name.  This
allows code like (define round round) to work as expected.

ice-9/boot-9.scm

index 7756b4c..e5bdd67 100644 (file)
               ;; the standard eval closure defines a binding
               (module-modified m)
               b)))
-      (and (module-binder m)
-          ((module-binder m) m v #t))
-      (begin
-       (let ((answer (make-undefined-variable)))
-         (module-add! m v answer)
-         answer))))
+
+      ;; No local variable yet, so we need to create a new one.  That
+      ;; new variable is initialized with the old imported value of V,
+      ;; if there is one.
+      (let ((imported-var (module-variable m v))
+           (local-var (or (and (module-binder m)
+                               ((module-binder m) m v #t))
+                          (begin
+                            (let ((answer (make-undefined-variable)))
+                              (module-add! m v answer)
+                              answer)))))
+       (if (and imported-var (not (variable-bound? local-var)))
+           (variable-set! local-var (variable-ref imported-var)))
+       local-var)))
 
 ;; module-ensure-local-variable! module symbol
 ;;