From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Peter Brett Newsgroups: gmane.lisp.guile.user Subject: Re: Multiple parallel environments Date: Thu, 30 Jul 2009 16:19:36 +0100 Message-ID: References: <87r5vyl3cr.fsf@gnu.org> <878wi6jklf.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1248967371 2626 80.91.229.12 (30 Jul 2009 15:22:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 30 Jul 2009 15:22:51 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Jul 30 17:22:44 2009 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 1MWXSu-0000YK-3M for guile-user@m.gmane.org; Thu, 30 Jul 2009 17:22:44 +0200 Original-Received: from localhost ([127.0.0.1]:47601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWXSt-0002Uq-E7 for guile-user@m.gmane.org; Thu, 30 Jul 2009 11:22:43 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MWXQG-0007Ge-Df for guile-user@gnu.org; Thu, 30 Jul 2009 11:20:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MWXQB-00079q-QY for guile-user@gnu.org; Thu, 30 Jul 2009 11:19:59 -0400 Original-Received: from [199.232.76.173] (port=34119 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MWXQB-00079c-7M for guile-user@gnu.org; Thu, 30 Jul 2009 11:19:55 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:37568 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MWXQA-0004p5-Ey for guile-user@gnu.org; Thu, 30 Jul 2009 11:19:55 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MWXQ6-0006u9-FE for guile-user@gnu.org; Thu, 30 Jul 2009 15:19:50 +0000 Original-Received: from 131.227.8.63 ([131.227.8.63]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 30 Jul 2009 15:19:50 +0000 Original-Received: from peter by 131.227.8.63 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 30 Jul 2009 15:19:50 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 87 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 131.227.8.63 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:ThFHDPVTAZSXFZmulwXoC5wJMOE= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:7379 Archived-At: ludo@gnu.org (Ludovic Courtès) writes: > Hello! > > Peter Brett writes: > >> ludo@gnu.org (Ludovic Courtès) writes: > > [...] > >>> What do you mean by "environment"? All the global variables associated >>> with a given file in the editor? >> >> Sort of. The whole of Guile's top level bindings at that point. (The >> per-directory config is literally loaded as a Scheme script, so it >> could define and redefine functions and variables at will). > > Then you are looking for Guile's nifty first-class modules. The module > API is unfortunately lightly documented (info "(guile) Module System > Reflection"). Indeed. Should I file a feature request for "more useful documentation of the Guile module system"? IMHO, examples like my use case would be very useful and informative. How much will the way they work be changing in the next stable series of Guile releases? How will they work w.r.t. R6RS modules? >>> What do you mean by "save"? Serialize to a file the "environment" >>> associated with a file (or the difference compared to the initial >>> environment)? >> >> It doesn't need to be serialised -- I don't even need to be able to >> get a C pointer to it! -- it just needs to be "stashed" somewhere so >> that I can "rewind" Guile's toplevel bindings to that point at a later >> time. >> >> Essentially, I want each directory/"project" to be able to define its >> own functions, include its own modules etc. without stomping over >> another project that happens to be loaded into the application at the >> same time. > > Easy! :-) > > What you would do is create one module for each file/project/directory: > > (define (make-per-file-module name) > (let ((m (make-module))) > (set-module-name! m name) ;; give the module an optional name > (beautify-user-module! m) ;; populate the module with the > ;; default bindings > m)) Something like the following? SCM create_module_for_dir (char *c_path) /* Path is a UTF-8 string */ { SCM magic = scm_from_locale_symbol ("*magic-dir-module*"); SCM path = scm_from_locale_symbol (c_path); SCM module = scm_resolve_module (scm_list_2 (magic, path)); scm_remember_upto_here_2 (magic, path); return module; } Not entirely sure how to emulate "beautify-user-module!" in C... any ideas? > Then you create one such module for each file/directory/etc. and somehow > associate it with said file/directory/etc. (with an alist, a hash table, > or something similar). When entering a file associated with that > module, you just have to make it current: > > (define (enter-file-buffer file) > (set-current-module! (lookup-per-file-module file))) > > And voilà! :-) > > Hope this helps, This does help, thanks! Peter :-) -- Peter Brett Remote Sensing Research Group Surrey Space Centre