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


>>>>> "Chris" == Chris Bitmead <Chris.Bitmead@misys.com.au> writes:

Chris> After reading the guile ref manual, it's not clear to me that modules do
Chris> much more than slib's require -

The difference is the guile modules has scoping implications, whereas
the slibs require mechanism doesn't.

If you use `require', this is exactly equivalent to using `load',
except that `require' is smart enough not to do the load if it has
already been done. The file to load or require adds a specific symbol
to a features list, and `require' simply checks whether the symbol is
there, and if not, loads the file.

Guile modules goes to work, when you have a `define-module' in a
file. After evaluating that, all following definitions are hidden,
unless explicitly exported.

Here a simple example, which you may do on the command line:

	;;save current module
	(define top (current-module))
	(define x 1)
	x ; yields 1

	;;create and switch to a new module, called (foo bar)
	(define-module (foo bar))
	(define x 2)
	x ; yields 2

	;;switch back to the initial module
	(set-current-module top)
	x ; yields 1 again


Chris> I'm sure they do, it's just that either I'm too thick to see it, or the
Chris> documentation is sadly lacking.

Chris> The problem is I'm having wierd things happen, and I suspect it's something
Chris> to do with modules -
Chris> things like symbols that exist, but then I load some code and they are not
Chris> available to be used
Chris> in the loaded code. From what I read in the ref manual, there is no reason
Chris> for me to believe modules
Chris> would cause this, but there is too much I don't understand about modules.




>> chrisb@ans.com.au writes:
>>> 
>>> What if any is the relationship between slib's (require ..) and guile's
>>> (use-module ...)
>>> 
>>> Should I favour one over the other? Are they interchangable? Are they
>>> meant for
>>> different purposes?
>>> 
>> 
>> One works for Guile modules, the other works for slib packages. They
>> are not interchangable, AFAIK there is no package you can load using
>> both methods. Personally, I would like to see slib packages made
>> visible in the Guile module namespace, I have some ideas on this but I
Chris> might wait >for Godot before taking a crack at it.
>> 
>> - Maciej