guile-devel
[Top][All Lists]
Advanced

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

Re: module naming


From: thi
Subject: Re: module naming
Date: Fri, 20 Apr 2001 12:46:16 -0700

   From: Neil Jerram <address@hidden>
   Date: 20 Apr 2001 17:05:14 +0100

   >>>>> "Rob" == Rob Browning <address@hidden> writes:

       Rob> I think I agree.  The whole taxonomy approach, has, in other
       Rob> contexts often provided endless fodder for organizational
       Rob> weinering, with long arguments debating what, in the end, for
       Rob> some tasks trying to use a formal taxonomy, are irrelevant
       Rob> distinctions.

   De facto, a few of us are following this approach already anyway - see
   (ttn ...), (mgrabmue ...), (gui ...).

people prefer different ontologies/taxonomies.  so the right thing to do
is for module authors to provide what they find useful and document
their (ideally stable ;-) interface, and for guile to provide
full-featured aliasing so that module users can easily realize their
preferred view.  this reduces bitch/moan factor for everyone.

there are two aliasing opportunities: the module name and the bindings
inside each module.  in the current system, bindings aliasing can be
done manually:

  (define NEW-NAME OLD-NAME)

and it can also be done programmatically (see below, and also (ttn edit)
macros `FROM:gb' and `simple-gb->e:' for examples).  see also 1998 or
1999 thread where i propose making `process-define-module' extensible,
and provide a patch.

module name aliasing requires changes to ice-9/boot-9.scm proc
`resolve-module'.  a module name alias must be like a symlink, able to
alias module trees as well as individual modules.

thi


________________________________________________________
;;; ttn/moduleutils.scm --- module system hackery

;; $State: Rel $:$Name:  $
;;
;; Copyright (C) 2000-2001 Thien-Thi Nguyen
;; This file is part of ttn's personal scheme library, released under GNU
;; GPL with ABSOLUTELY NO WARRANTY.  See the file COPYING for details.

;;; Commentary:

;; This file has code originally in @.scm and ls.scm (before 0.04 release).
;; Those files were deleted as a result.  Their histories were insubstantial.

;;; Code:

(define-module (ttn moduleutils))

(defmacro @ args                        ; quality is the moment of perception
  `(lambda (sym)
     (variable-ref (module-variable (resolve-module ',args) sym))))

(defmacro import-from-module (other-module-name . names)
  "Import into current module from OTHER-MODULE-NAME variables NAMES.
Each element of NAMES is taken to be either a variable name, or
a pair (OLD-NAME . NEW-NAME) describing the mapping to be used.
OLD-NAME needs to be defined in OTHER-MODULE-NAME, though it need not
be exported."
  `(begin
     ,@(map (lambda (name)
              (if (pair? name)
                  `(define ,(cdr name) ((@ ,@other-module-name) ',(car name)))
                  `(define ,name ((@ ,@other-module-name) ',name))))
            names)))

;; snarfed from THUD
(defmacro reexport-from-module (other-module-name . specifically)
  "Re-export variables from module named OTHER-MODULE-NAME.
If optional args SPECIFICALLY is the empty list, all public variables
from OTHER-MODULE-NAME are exported, otherwise, each element in SPECIFICALLY
is taken to be either a symbol naming a variable to be exported, or a pair of
symbols of the form (OLD-NAME . NEW-NAME) describing the mapping to be used.
OLD-NAME should name an exported variable in OTHER-MODULE-NAME."
  `(let ((cur-mod   (current-module))
         (other-mod (resolve-module ',other-module-name))
         (spec      (map (lambda (x) (if (pair? x) x (cons x x))) ; for assq
                         ',specifically)))
     (let ((add! (lambda (old-name new-name)
                   (module-add! (module-public-interface cur-mod)
                                new-name
                                (module-variable other-mod old-name)))))
       (module-map (lambda (sym x)
                     (if (eq? '() spec)
                         (add! sym sym)
                         (let ((try (assq sym spec)))
                           (and try (add! (car try) (cdr try))))))
                   (module-public-interface other-mod)))))

(define (bind-in-the-scm-module! name obj)
  "Add variable named NAME w/ value OBJ to `the-scm-module'."
  (module-define! the-scm-module name obj))

(export @
        import-from-module
        reexport-from-module
        bind-in-the-scm-module!)

;;; ttn/moduleutils.scm ends here



reply via email to

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