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: Module Import Bindings for Non-Main Classes


On 10/26/2011 03:01 PM, Per Bothner wrote:
On 10/26/2011 11:45 AM, Taylor Venable wrote:
Hi everybody, another question; this time about importing module fields.
[...]
Why are test-b and test-c bound to the values they have in Alpha only
when running Beta as the main class? How can I get the "right" bindings
when running Gamma as the main class? I must be missing something
obvious, but I can't figure it out. Thank you for any advice.

Quick answer: compile alpha.scm with --module-static-run or add (module-static 'init-run) to alpha.scm.

Thanks much for the quick response. That does indeed make it work how I expected.


Read http://www.gnu.org/software/kawa/Module-classes.html#How-a-module-becomes-a-class

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



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.

Consider that evaluating the body of alpha.scm means evaluating various
expression and performing various initializations/assignments. How should these
effects be performed? Obviously, they have to be in some compiler-generated method,
but which method, and when and how does this method get invoked? One issue is that if
we made --module-init-static run the default (i.e. bodies automatically evaluated
when the class is initialized) then you have no way of passing command-line arguments
- since the body would be evaluated before main starts.

Great explanation, that makes perfect sense.


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?


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