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]

Re: require vs use-modules




Mmm. I think I'm starting to get it! Put this stuff in the manual!




[I accidently sent the previous mail too early]

`use-modules' does two things. First it checks whether the module
already exists. If it doesn't, it loads the file pointed to by the
module name. After that, it imports all names public in the module,
into the current module.

Suppose the definitions

 (define-module (foo bar))
 (define z 4)
 (define-public y 5)

was put into some appropriately named file. Doing a

 (use-modules (foo bar))

would load the file and this would create the (foo bar) module. Then
it would import the symbol `y'. However, `z' would still be undefined,
since this is not public in (foo bar).

You may also load the file with `load' and then use `use-modules'. The
load would have created the module, so `use-modules' would not search
for it, but would skip right to the part where it imports the public
symbols from (foo bar).

You may also do evaluate `define-module' as often as you want. When
you do, you switch context so that you are inside that module, having
access to all its symbols, whether public or not. However, you will
not have access to other symbols which resides in other modules which
are not explcitly imported (with `use-modules'), ie. `apropos' will be
undefined after changing to (foo bar).

Hope it helps a bit.


---------------------------+-----------------------------------------------
---
Christian Lynbech          | Telebit Communications A/S
Fax:   +45 8628 8186       | Fabrik 11, DK-8260 Viby J
Phone: +45 8628 8177 + 28  | email: chl@tbit.dk --- URL:
http://www.telebit.dk
---------------------------+-----------------------------------------------
---
Hit the philistines three times over the head with the Elisp reference
                                        manual. - petonic@hal.com (Michael
                                        A. Petonic)