From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stephen Compall Newsgroups: gmane.lisp.guile.user Subject: Re: load in environment Date: Fri, 06 Jul 2007 00:26:16 -0400 Message-ID: <468DC468.6020609@member.fsf.org> References: <468DBA60.9040804@wilsonjc.us> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1183697373 10533 80.91.229.12 (6 Jul 2007 04:49:33 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2007 04:49:33 +0000 (UTC) To: Guile Users Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jul 06 06:49:31 2007 connect(): Connection refused Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I6fl5-00039o-0S for guile-user@m.gmane.org; Fri, 06 Jul 2007 06:49:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6fl4-0000Gc-4m for guile-user@m.gmane.org; Fri, 06 Jul 2007 00:49:30 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I6fkx-0000GP-H3 for guile-user@gnu.org; Fri, 06 Jul 2007 00:49:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I6fkw-0000Fv-1L for guile-user@gnu.org; Fri, 06 Jul 2007 00:49:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6fkv-0000Fb-J0 for guile-user@gnu.org; Fri, 06 Jul 2007 00:49:21 -0400 Original-Received: from uemail.evansville.edu ([192.195.225.14]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I6fkv-0002d3-4H for guile-user@gnu.org; Fri, 06 Jul 2007 00:49:21 -0400 Original-Received: from Epsilon-III.local ([70.169.18.214]) by uemail.evansville.edu with Microsoft SMTPSVC(6.0.3790.1830); Thu, 5 Jul 2007 23:24:26 -0500 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.4) Gecko/20070509 SeaMonkey/1.1.2 In-Reply-To: <468DBA60.9040804@wilsonjc.us> X-OriginalArrivalTime: 06 Jul 2007 04:25:10.0780 (UTC) FILETIME=[A415DBC0:01C7BF85] X-detected-kernel: Windows 2000 SP4, XP SP1+ X-Greylist: delayed 1324 seconds by postgrey-1.27 at monty-python; Fri, 06 Jul 2007 00:49:21 EDT X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6020 Archived-At: 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 Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user