This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: the right way to compile and load modules
- From: mikel evins <mevins at me dot com>
- To: Per Bothner <per at bothner dot com>
- Cc: mikel evins <mevins at me dot com>, kawa at sourceware dot org
- Date: Tue, 13 May 2014 20:49:55 -0500
- Subject: Re: the right way to compile and load modules
- Authentication-results: sourceware.org; auth=none
- References: <9F312D97-98C6-4F47-BDD9-B6CAF3868A28 at me dot com> <5371CFD0 dot 7070708 at bothner dot com> <7D1A5D60-5997-4B7A-9176-8F6FA315F016 at me dot com> <ED4375FE-30EE-4ABC-A9DC-2C6C4D67A87A at me dot com> <54132084-D633-4AAA-B2A4-9008FF37F779 at me dot com> <5372CA25 dot 7050602 at bothner dot com>
On May 13, 2014, at 8:43 PM, Per Bothner <per@bothner.com> wrote:
> 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.
I'd rather not do anything that's not recommended, and I won't unless there's no other way to make things work.
> 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.
Yeo, that squares with the behavior I saw.
> 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")' --
That seems like the way to go for my project. I use a project-specific shell script to launch kawa anyway.
> You can also use ~/.kawarc.scm.
Not as good. I don't necessarily want to limit use of kawa to this one project, so I don't necessarily want to require its sources every time I start kawa.
> 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.
That also seems fine to me. Thanks for the advice.
>> 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?
Sure. In a few minutes.