From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Marius Vollmer Newsgroups: gmane.lisp.guile.user Subject: Re: Two questions about the guile module system Date: 05 Apr 2003 19:00:38 +0200 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <87pto0c215.fsf@zagadka.ping.de> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1049564350 25381 80.91.224.249 (5 Apr 2003 17:39:10 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 5 Apr 2003 17:39:10 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Apr 05 19:39:08 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 191rdD-0006b7-00 for ; Sat, 05 Apr 2003 19:39:08 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 191rcw-0006WS-0B for guile-user@m.gmane.org; Sat, 05 Apr 2003 12:38:50 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 191rbC-0005nB-00 for guile-user@gnu.org; Sat, 05 Apr 2003 12:37:02 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 191rZB-00051j-00 for guile-user@gnu.org; Sat, 05 Apr 2003 12:34:58 -0500 Original-Received: from mail.dokom.net ([195.253.8.218]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 191r2C-0000iJ-00 for guile-user@gnu.org; Sat, 05 Apr 2003 12:00:52 -0500 Original-Received: from dialin.speedway42.dip145.dokom.de ([195.138.42.145] helo=zagadka.ping.de) by mail.dokom.net with smtp (Exim 3.36 #3) id 191r2w-0000jf-00 for guile-user@gnu.org; Sat, 05 Apr 2003 19:01:39 +0200 Original-Received: (qmail 3787 invoked by uid 1000); 5 Apr 2003 17:00:39 -0000 Original-To: Joris van der Hoeven In-Reply-To: Original-Lines: 100 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 Original-cc: contact@texmacs.org X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1768 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1768 Joris van der Hoeven writes: > In guile 1.3.4, I could put the following in my main initialization file: > > (use-modules (boot-stuff)) ; defines export-from > (use-modules (std-lib-1) ... (std-lib-n)) > (export-from (std-lib-1) ... (std-lib-n)) > ... > (use-modules (appl-mod-1) ... (appl-mod-k)) > ... > > When doing this, I can use all variables exported by > the standard libraries std-lib-1, ..., std-lib-n > inside appl-mod-1, ..., appl-mod-k. > > Unfortunately, this mechanism breaks in guile-1.6.3. > The point is that, during the importation of > appl-mod-1, ..., appl-mod-k, the outer context is lost. The relevant difference between guile 1.3.4 and 1.6 is that in version 1.6, you are initially in the (guile-user) module, while in 1.3.4 you are probably in the (guile) module. What module you are in is of course the module that you are exporting from with 'export-from'. Now, the (guile) module is special in that its bindings are automatically visible in all normal modules. The ones from (guile-user) are not automatically visible. So when you export-from the (guile) module, the exported bindings become visible in all other modules, including in the (appl-mod-...) modules. To access bindings exported from (guile-user), you must explicitely 'use' it, just like any other module. I think it is best to change your code to (define-module (std-libs)) (use-modules (boot-stuff)) ; defines export-from (use-modules (std-lib-1) ... (std-lib-n)) (export-from (std-lib-1) ... (std-lib-n)) ... (use-modules (appl-mod-1) ... (appl-mod-k)) ... and add a (use-modules (std-libs)) to any module that needs it. (Probably all (appl-mod-...) modules and maybe also the (std-lib-...) modules.) > It seems that only a very minimal context is visible > inside the application modules. A module starts out with all bindings from the (guile) module visible. What you did in Guile 1.3.4 was to 'accidentally' add bindings to the (guile) module, which of course made them automatically visible everywhere. > > (Btw, there is also module-map which might be more natural to use in > > place of module-for-each.) > > What does that routine do? It is to module-for-each what map is to for-each: it returns a list of the results of applying the proc to each symbol/variable pair. You can use it like: (define-macro (re-export-from . which-list) (define (module-exports which) (let* ((m (resolve-module which #f)) (m-public (module-ref m '%module-public-interface #f))) (module-map (lambda (sym var) sym) m-public))) (let ((l (apply append (map module-exports which-list)))) `(re-export ,@l))) > > > This makes it impossible to enhance the root environment > > > with even a single macro like 'define-my-module'. > > > > I find this not to be true, but it is indeed tricky to reason about > > the context in which modules are loaded. > > So how can I make things such that whenever I declare a new module, > then all symbols which are visible in the initial context > are available by default? You will need to put those enhancements into the (guile) module. I'm not sure whether that is unconditionally a good idea since you are changing the nevironment for all code, not just for your own. So, a better alternative is maybe to make a new 'use-modules' variant that makes sure that modules are loaded in a controlled environment. > This important, since I also noticed that even the C++ routines > which I glued to Guile are not available inside my modules! They are probably in the (guile-user) module as well. -- GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405 _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user