On 25 Nov 2009, at 09:05, Ge Wang wrote:
This is indeed actually a bug, not a feature! Static variables are not initialized correctly (and currently need to be explicited initialized outside the class definition). We hope to address this in the near future!
There two different concepts in play: the class body as code to be run when an element is initialized, and as a name space. The class static functions are in the latter category, and can call class static data, which then should be initialized before such use. But one could combine the two by some syntax (though T do not know if it is useful). For example, writing class A { static: 3 => int m; dynamic: 3 => static int n; ... } would indicate that m is in a static data segment and should be initialized when the class is loaded, whereas n is initialized when a class object is initialized. Then n will be initialized ever time a class object is initialized, but the idea is that this should be possible if initializing is something more complex, like opening files or creating other side effects (as Kassen suggested). But perhaps one can just use a function for this n. That is, if all static objects are initialized, one can achieve special side effects using the construct: class A { 3 => static int m; static int n; n_(); static int n_() { 3 => n; } } (though n here first gets initialized to 0). Hans