This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: difference between (load "package.foo.bar") and require?


Dominique Boucher wrote:

The semantics of (load "file") and (require <modulename>) is quite different
and serves different purposes.

To add a little:


load is mostly used for loading Scheme source *files*, though it
can also load a Scheme source file compiled using compile-file.
(See the hanhdling of testing.scm/testing.zip in the testsuite.)
As load is "standard", it should follow standard Scheme semantics.

Require works on *modules*.  In principle a module can be any class,
whether compiled from Scheme and Java, but what it does with the
module depends on the public fields of the module.  Basically,
it adds a new binding to the *local* environment for each public
field.  The name of the binding is derived from either the field
name, or the result of getName() if the field value implemented Named.
Instance fields require an instance to be allocated, which require does.

Require provides namespace management.  The imported names are visible
at compile-time, and they are not re-exported (by default).

When loading a file, all top-level definitions are added to the top-level
interaction environment. The loading is done by 'load' using a custom class
loader. That's why it does not take into account the .jar files.

It does use the same ClassLoader as when you're evaluating expressions, which is an ArrayClassLoader. If you load a file-compiiled-to-zip, it uses a separate ZipLoader.

When requiring a module B from a module A, you make the exported bindings of
B visible to the importing module (A). This has nothing to do with the
top-level environment. This is mainly to produce more efficient code.

And namespace separation - plus better compile-time error checking. (Require is syntax mostly implemented at compile=time; load is a function executed at run-time.)

If you want to access some loaded code from within Kawa modules compiled
using kawa -C, you'll have to use 'eval'.

Not sure what you're referring to here. -- --Per Bothner per@bothner.com http://per.bothner.com/


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