Hi, Velli-Pekka!<br><br><div><span class="gmail_quote"><br></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&nbsp;THis is based on my<br>object-oriented knowledge in general and might be incorrect in the context
<br>of ChucK. You have been warned, &lt;smile&gt;.</blockquote><div><br>I&#39;ll be fine &lt;smile&gt;<br><br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
First of all, I think&nbsp;&nbsp;the subject is slightly ambiguous. In programming<br>jargon it could mean one of two things:<br>Members of a class as in the data members e.g. doing something to all data<br>fields of a particular object or class gloablly via reflection. OR what you
<br>ment doing something to every instance of a class.</blockquote><div><br><br>Yes, sorry, that was my oops. I meant all instances.<br><br>So; we&#39;d have a forest made up of lots of instances of the tree class and I want to burn the whole thing down by expressing &quot;every tree is on fire&quot;. My &quot;member&quot; type here came from me mucking it up with set theory where such things are very easy to express; you&#39;d simply go &quot;if something is a tree then it&#39;s also on fire&quot; and be done. That&#39;s what you get when your first real language was Prolog &lt;blush&gt;.
<br>&nbsp;<br>Classes have a certain set-theory feel to me, where extending them becomes like sub-sets. Makes sense as a mental model for creating them but clearly less so when adressing them.<br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hmm if it is their own thing, it is an instance i.e. non-static variable,<br>not a class variable. A class variable is like a global variable, except<br>that it is restricted in a class. In other words, all the count methods
<br>would modify the same variable if the variable is a static variable. This is<br>assuming ChucK&#39;s static works like in Java, I&#39;m not sure about that.</blockquote><div><br>I think it does, at least it works like you explain here.
<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>The easiest way to do this would be to have a class method named<br>resetCounter and calling it for each of the instances you have in a loop.
</blockquote><div><br>That&#39;s exactly what I did now. It turns out I only have 8 instances right now so this is still very managable.<br><br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Alternatively, you could keep track of all the instances in a static array<br>in the class, and then call the reset method for all the elements in the<br>array. But this latter thing is more complicated and might differ garbage
<br>cllection, if it is based on reference counting the objects.</blockquote><div><br>Yes, I see, and it would also come down to the same thing, except with house-keeping automated. For -say- a dozen instances I can keep track of it by hand.
<br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>Static functions are always called on a class, not on an object. </blockquote>
<div><br>Hmmmm, not nesicarily so in ChucK. It turns out I can call static functions on instances, it&#39;s just that it doesn&#39;t make any difference from calling them on the class itself. Probably just a syntactic convenience.
<br><br>So, static functions in classes only make sense if they act on other static members of that class and have no real other use? Wouldn&#39;t that mean a non-static function would be just as good aside from not being callable on the class itself?
<br><br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Unless you<br>pass in the object as a parameter but that&#39;s suspicious outside of certain
<br>scripting languages whose names start with p, in which it is the right way<br>to do it.</blockquote><div><br>Actually, I think that in ChucK you can pass objects as parameters, for axample if you write a function that will do something to a filter you can pass it the reference to a speciffic instance as a parameter. Not so suspicious, to me.
<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">That is because chucK does not know hwich object&#39;s variable you are<br>accessing. THink of it like this:
<br>If you call a non-static method, the variables you are likely to deal with<br>are particular to that instance of the class, although you can access and<br>modify static variables that all the instances share, too.<br>
If you call a static method, you are doing something global to all<br>instances, such as modifying a shared static variable. AS the variable is<br>shared, you don&#39;t have to have an instance to be able to refer to it.</blockquote>
<div><br>Right, yes, I see now.<br><br>In that case; would it be at all a bad idea to make a new sort of function that would act like I described? That sounds very usefull to me. Clearly something functionally identical could be made but that would mean additional structures to keep track of how many instances we have and what they are called which might complicated matters considderably. Clearly ChucK already has to keep track of those exact things anyway so why not make that info available to the program se we can do things like making all instances of the class &quot;person&quot; jump at the same time? Especially for things like polyphony and particle-based synthesis techniques that would be nice.
<br><br>(I&#39;m sure I&#39;m blundering over a lot of CS concepts right now)<br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&gt; about a nullpointer exception.<br>A semantic quibble, why is it called a null pointer if the language only<br>supports references? I&#39;ve been thinking the same about Java.</blockquote><div><br>Well, that&#39;s another question... I was thinking that ChucK should maybe have caught this when I tried running it like it did when I tried adding the &quot;this&quot; keyword (at that point I still thought I could get the function to execute for every instance in turn).
<br><br>&nbsp;</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hope this clarifies matters. IF not, I could try to demonstrate using a code
<br>sample.</blockquote><div><br>Totally clear now, thanks!<br><br>Kas. <br></div><br></div>