<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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!<br>

<br></blockquote><div><br>Ge, <br><br>I suspect you misread the exact issue under debate here. Consider;<br><br>class War<br>{<br>static int foo;<br>static Gain mix;<br>3 =&gt; static int bar;<br>}<br><br>foo is perfectly fine, I&#39;m sure we all agree there. mix is a a problem and that line in that form won&#39;t fly; it needs to be initialised from outside of the class. We can get around that using something like this;<br>
<br>class War<br>{<br>static Gain @ mix;<br>static fun void init() {new Gain @=&gt; mix;}<br>}<br><br>...that way we at least keep all of the definitions inside of the class and only need to call init() from outside. I think this is what you are refering to; this needs a fix and correct behaviour is quite clear.<br>
<br>The problem under debate is the &quot;bar case&quot;. bar, as a member, will be initialised at the definition of the class, it just won&#39;t have the value 3 without a instance of the class. Maybe I&#39;m misreading your post here, and you do see the setting of the value 3 as part of initialising bar in this case? As pointed out earlier, doing so is not without questions as we may also set the value using something like;<br>
<br>myFun() =&gt; static int bar; //or<br>myStaticFun() =&gt; static int bar; // or<br>myNonMemberFun() =&gt; static int bar;<br><br>...assuming all of those return a int. No problem arrises if all those do is return a int, but they may have side effects and might, in their definition, refer to non-build-in types, potentially leading to circular definitions and much more complicated demands on the order things are parsed in. Allowing this may lead to syntactically correct files that still can&#39;t be executed.<br>
<br>I think it may be fine if we only allow static member functions (of the given class) to set such values, but that would mean a extra syntactical constraint. That said; setting static constants would be very handy in -for example- determining the length of static UGen arrays for vm-wide routing without getting into magic numbers. Right now we can&#39;t do that and such numbers can&#39;t be defined as a part of the class they belong to without instantiating the class as well. This leads to some important numbers getting defined outside of the context in which they are important, which won&#39;t win any beauty awards; for that reason I sugest currently using something like my &quot;init()&quot; example above as that structure really helps when returning to code weeks later.<br>
<br>We can call the current situation a &quot;bug&quot; on the grounds of a line of code being only partially executed, but I don&#39;t think it&#39;s a simple bug where we can effortlessly say what should happen instead. One of my concerns is that we are very concerned with deterministic execution order in ChucK but that&#39;s no good if the execution order is very hard to predict.<br>
<br>Phew! :-)<br><br>Yours,<br>Kas.<br></div></div>