This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problems with tguile's unexec


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)))))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]