This is the mail archive of the guile@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] |
Todd Larason <jtl@molehill.org> wrote: > On 980805, Christian Lynbech wrote: > > Also, you may do a `(define-module (my own module))' which will make > > that module current. If you redefine a symbol here, the new definition > > will appear in all modules that use `(my own module)' (provided the > > symbol was exported of course). Use `(set-current-module the-root-module)' > > to get back to the default module. > > is that `(set-current-module the-root-module)' literal? Or do I need to > find the-root-module somehow? the external representation of a module is a list. `define-module' is a macro so its first arg, the list describing the module, need not be quoted. `define-module' implicitly does a `set-current-module'. `set-current-module' accepts a module object. the module object itself is a kind of record. `the-root-module' is a module object defined by ice-9/boot-9.scm. `(my own module)' is not a module object (it's a list of symbols). use `resolve-module' to return an actual module object given its list representation (quote it since `resolve-module' is not a macro). basically, you want something like: (set-current-module (resolve-module '(my own module))) here is an implementation of `@', which was discussed on this list a while ago. it returns an accessor procedure (a wormhole through the module system, i like to imagine) that can resolve one symbol. (defmacro @ args ; quality is the moment of perception `(lambda (sym) (variable-ref (module-variable (resolve-module ',args) sym)))) so, for example, you can do: guile> (define-module (my own module)) guile> (define (negative x) (- x)) ; in `(my own module)' guile> (define-module (somewhere else)) guile> (negative 3) => ERROR: Unbound variable: negative guile> (define peek-into-my-own-module (@ my own module)) guile> ((peek-into-my-own-module 'negative) 3) => -3 i use `@' for QA purposes, where punching holes in the paper bag is (sort of) justifiable. getting `@' visible to the current module is an exercise for the reader. (hint: what does `module-uses' tell?) thi