This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
Problems with tguile's unexec
- To: Greg Badros <gjb at cs dot washington dot edu>
- Subject: Problems with tguile's unexec
- From: thi <ttn at mingle dot glug dot org>
- Date: Tue, 19 Oct 1999 23:37:39 -0700 (PDT)
- Cc: guile at sourceware dot cygnus dot com
- References: <qrr1zatlao2.fsf@elwha.cs.washington.edu>
- Reply-To: ttn at netcom dot com
Greg Badros writes:
> Incidentally, is there a good way to write a module that exports
> symbols from a bunch of modules that it imports? E.g., a single
> module guile-all.scm that does the use-modules, and then another
> module can just use that one module and get at all the symbols?
please see below for `reexport-from-module', which seems to work for
THUD. besides export, renaming is also supported. (actually i think
i've posted this before, apologies to all for the redundancy. (where
are you, o refbot?))
sample usage:
(define-module (a b c)
:use-module (x y z)
:use-module (p d q))
(reexport-from-module (x y z))
;; all exported definitions from (x y z) are now exported from (a b c)
(reexport-from-module (p d q) (pretty (damn darn) quick))
;; only `pretty', `damn' and `quick' are exported from (a b c),
;; but `damn' is exported as `darn'.
this code works w/ the distributed guile, but if you feel adventurous,
you may wish to scan recent (< 2mo) guile mailing list archives for a
small patch to boot-9.scm i posted that adds a hook to extend
`define-module'. w/ that change, a more fundamental integration of
system-provided and user-defined module specification is possible.
(i hope some form of hook will be added, it seems to be an obvious and
simple addition...)
thi
------------------------
;;; Managing THUD modules and symbols
;; Re-export variables from module named OTHER-MODULE-NAME. If 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.
;;
(defmacro reexport-from-module (other-module-name . specifically)
`(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)))))