This is the mail archive of the kawa@sourceware.org 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: the right way to compile and load modules


On 05/13/2014 06:12 PM, mikel evins wrote:
My question was in the subject line: what's the right way to compile and load modules. By "right" I mean a way that works both when batch-compiling kawa for packaging in a jar and when interactively loading sources for repl-session development.

The answer appears to be that for interactive loading, one should use a load file that consists of a series of require forms, one for each source file, and the load file should reside in the same directory as the sources. That approach loads all of our code and silences the warnings I was previously seeing. (I still see warnings about symbols that are not visibly referenced anywhere, but that is an accurate and informative warning, so I have no complaint).

Mixing load and require can be a bit fragile, but if it works for you that's ok.
In general I say it's best to avoid using either load and eval.
(People tend to overuse them.)

I just checked in a fix to this problem:

#|kawa:1|# (require "foo.scm")
/dev/stdin:1:1: not found: /dev/foo.scm (No such file or directory)

This mysterious problem was because the filename of the default input port
is "/dev/stdin" and require resolves the specified filename against the
current filename.  Ooops.  Using require with a filename should work now.

If you need to require multiple source files in the repl, you can use the -e option:

$ kawa -e '(require "foo.scm")' -e '(require "bar.scm")' --

You can also use ~/.kawarc.scm.

Even better is you put all the require forms in a file file, and require that.
However, in that case you need to add module-exports statements to re-export
the definitions you need.

For compiling, the answer is that each source file must have a module-export form that exports each symbol that is used in some other source file. That's contrary to what the kawa docs say, but I found that in practice I saw a number of problems if I didn't use module-export forms to expose a file's definitions. In some cases kawa refused to complete the compile; in others it built everything without complaint, but crashed into a stack trace at runtime on an undefined location.

Using module-export cures these symptoms.

Since this is contrary to the kawa docs, I'm open to the possibility that I'm still doing something wrong that causes the unexpected behavior.

I don't know.  Sounds mysterious.  If you have *no* module-exports it's supposed to be equivalent to
exporting everything that isn't define-private etc.  There are some exceptions - for examples names that
are imported using require aren'r re-exported by default.Again, perhaps you can show us a simple test-case?

--
	--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]