guile-user
[Top][All Lists]
Advanced

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

Re: load in environment


From: Stephen Compall
Subject: Re: load in environment
Date: Fri, 06 Jul 2007 00:26:16 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4) Gecko/20070509 SeaMonkey/1.1.2

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




reply via email to

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