Jon Wilson wrote:
The second way is to make the desired environment temporarily be the current module:

(define load-env-2 filename env)
 (let ((real-current-module (current-module)))
   (set-current-module! env)
   (load filename)
   (set-current-module! real-current-module)))

The second way has the advantage of not reinventing the wheel when it comes to the read-eval loop, but looks rather strange.

It is a sensible enough pattern, easily made exit/reentry-safe with dynamic-wind in Scheme:

(define (load filename . env-lst)
  (if (null? env-lst)
      ((@ (guile) load) filename)
      (load-env-2 filename (car env-lst))))

(define (load-env-2 filename env)
  (let ((old-cm #f))
    (dynamic-wind
      (lambda ()
        (set! old-cm (current-module))
        (set-current-module! (environment-module env)))
      (lambda () (load filename))
      (lambda ()
        (set-current-module! old-cm)))))

What other Guile state might you want to modify in the dynamic context of a load, though?

--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
But you know how reluctant paranormal phenomena are to reveal
themselves when skeptics are present. --Robert Sheaffer, SkI 9/2003


_______________________________________________
Guile-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/guile-user

Reply via email to