chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] The point of 'provide'


From: Peter Bex
Subject: [Chicken-users] The point of 'provide'
Date: Sun, 3 Jan 2010 18:28:53 +0100
User-agent: Mutt/1.4.2.3i

Hi all,

I had a problem today which I already had before: when you define a
module, you cannot (use ) it unless you also (provide ) the extension:

#;1> (module foo (bar) (import chicken scheme) (define (bar) (print "bar")))
; loading /usr/pkg/lib/chicken/4/chicken.import.so ...
; loading /usr/pkg/lib/chicken/4/scheme.import.so ...
#;2> (use foo)
Error: (require) cannot load extension: foo

 ....

To fix this:

#;2> (provide 'foo)
#;3> (use foo)
#;4> (bar)
bar


However, when you stick the module inside a file, other strange things
happen:

#;1> (use foo)
Error: (import) during expansion of (import ...) - cannot import from undefined 
module: foo
#;1> (load "foo.scm")
; loading foo.scm ...
; loading /usr/pkg/lib/chicken/4/chicken.import.so ...
; loading /usr/pkg/lib/chicken/4/scheme.import.so ...
#;2> (use foo)
; loading ./foo.scm ...
#;3> (bar)
bar

Note the fact that first it can't find foo.scm (as the current working
dir is not in the path searched by USE).  However, after loading it,
suddenly USE can find the file and it _reloads_ the file.

Reloading the file is wrong behaviour, IMHO, because the file is already
loaded, and reloading it will wreak havoc if the module defines global
variables to keep track of things: those are reset.  It will also rerun
any side-effects that are caused by forms on the module's toplevel.

I understand that I can fix this by putting the (provide 'foo) in
foo.scm, or in the file that LOADs it, so afterwards it can be USEd
safely.  What I don't understand is why this can't be handled
automatically by the MODULE form.  In fact, _something_ registers the
fact that that module comes from this loaded file.  Since this is
registered, the system should also already know that this can only be
because the module's code is already loaded.  Why the reload upon USE?

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth




reply via email to

[Prev in Thread] Current Thread [Next in Thread]