This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Question regarding modules and module-export in Kawa
- From: Per Bothner <per at bothner dot com>
- To: alex mitchell <alexm at nus dot edu dot sg>
- Cc: kawa at sources dot redhat dot com
- Date: Tue, 28 Apr 2009 21:17:04 -0700
- Subject: Re: Question regarding modules and module-export in Kawa
- References: <C61DE087.1960F%alexm@nus.edu.sg>
On 04/28/2009 07:46 PM, alex mitchell wrote:
In moduletest.scm:
(module-export make-count)
; simple counter
(define (make-count)
(let ((count 0))
(lambda ()
(begin
(set! count (+ count 1))
(display count)))))
If I run this, I see the following warning:
#|kawa:1|# [...]/moduletest.scm:1:16: 'make-count' exported but never
defined
The problem is that when you evaluate a file it loads and evaluates
command-by-command, rather than processing the whole file. This is
an awkward inconsistency which ties in with compatibility, user
expectations, and macros. See the comment and conditiona in the
loadSource method in kawa/standard/load.java.
We might be able to "fix" this if we fixed the compiler so it
automatically compiles and evaluates macros before their first
use, even if defined in the same file.
On the other hand, when you *compile* a module, the whole file is
read in as a unit, first. (There is some magic to support
mutually referential modules.) So that works:
kawa -C moduletest.scm
You can also put a (begin ...) block around the entire source file,
to force it to be processed as a unit.
Despite this, the counter seems to work:
#|kawa:2|# #|kawa:3|# (define my-count (make-count))
#|kawa:4|# (my-count)
1
#|kawa:5|# (my-count)
2
However, if I require the module in another file, as follows:
(require "moduletest.scm")
(define my-count (make-count))
(my-count)
I get this:
#|kawa:1|# [...]/moduletest.scm:7:20: unbound location exception evaluating
count from Field:moduletest$frame.count - java.lang.NullPointerException
at gnu.expr.ReferenceExp.apply(ReferenceExp.java:106)
at gnu.mapping.CallContext.runUntilDone(CallContext.java:251)
at gnu.mapping.CallContext.getFromContext(CallContext.java:280)
at gnu.expr.Expression.eval(Expression.java:24)
at gnu.expr.ApplyExp.apply(ApplyExp.java:63)
[...]
at kawa.repl.main(repl.java:844)
This is fixed in the SVN version of Kawa.
--
--Per Bothner
per@bothner.com http://per.bothner.com/