Module Import Bindings for Non-Main Classes
Per Bothner
per@bothner.com
Wed Oct 26 19:45:00 GMT 2011
On 10/26/2011 12:22 PM, Taylor Venable wrote:
> Thanks, I was reading that page but not looking in the right place. It
> also says: "If 'init-run is specified, in addition the module body is
> evaluated in the class's static initializer. (Otherwise, it is run the
> first time it is require'd.)" That makes me think that the following
> modification alone should work (that is, without using the init-run in
> alpha.scm), but it does not:
>
> (module-name "com.example.Beta")
>
> (require com.example.Alpha)
>
> (define (test)
> (display test-a) (newline)
> (display test-b) (newline)
> (display test-c) (newline))
require and import are equivalent - both cause the imported module's
initializer (including the body) to be run.
The problem is gamma. It does not use either import or require,
so it just runs the Beta:test method *without insuring that Beta
has been initialized* - which means that Alpha hasn't been initialized
either.
> What it says in the doc sounds good to me: if you require the module,
> the module body will be evaluated, so that any fields within the module
> are properly initialized for use that will come later. (Surely, if I
> require it then I intend to use it in some way.) I would imagine that
> would be good if it worked for the import syntax in addition to require.
It does, as far as I know.
> I don't understand how the different behaviour between using Beta and
> Gamma as the main class arises from this, however. Shouldn't the module
> body of Alpha not be evaluated in both cases?
No - because the module body of Beta is not evaluated.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list