<div><font face="Monaco" style="font-size: 12px;">Hey Wolfgang,</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">So I wanted to get back to you about this because this was something that I had messed with years ago.  But when I looked for my modified code, I couldn't find it.  So, I looked at the latest source and discovered that the stub had been removed, the code cleaned up under the hood, making my hack unviable.  </font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">I took another stab at it.  Since, from the user's perspective, the internal object ID isn't very useful, I removed that from the toString() method.  Now, when you call toString() on an object, it returns a string representation of the class name.  This is helpful in programmatically (albeit hackishly) creating a safe object coercion framework, if that's your game.</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">Here's the link to the source:</font></div><div><font face="Monaco" style="font-size: 12px;">http://michaelclemow.com/projects/chuck/chuck-1.3.1.3_toString-modification.zip</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">When you unpack the archive, there will be an compiled binary for Mac OSX (Intel) called mcchuck, which is what I used to call my version.  It makes me think of McDonalds…  </font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">Anyway, the code compiles the normal way, if anyone else wants to try it on another system.</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">There is also a trivial example in a new examples folder here: examples/tostring/test.ck</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">Consider the following code:</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;">--------</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">// Object toString() modification</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">SinOsc s;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">Object obj;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">Shred sh;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><<< s.toString(), obj.toString(), sh.toString() >>>; // should print: SinOsc, Object, Shred</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">if( s.toString() == "SinOsc" ) {    // true</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><span class="Apple-tab-span" style="white-space:pre">     </span><<< s.toString() + " type verified programatically!" >>>;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">} else {</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><span class="Apple-tab-span" style="white-space:pre">     </span><<< "bummer..." >>>;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">}</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">// here's where things get interesting/dangerous...</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">s @=> UGen u;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><<< "this UGen is a...", u.toString() >>>;  // SinOsc!</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">if( u.toString() == "SinOsc" ) {  </span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><span class="Apple-tab-span" style="white-space:pre">     </span>u $ SinOsc => SinOsc ss;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><span class="Apple-tab-span" style="white-space:pre">     </span><<< "safe coercion of UGen to SinOsc complete!" >>>;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">} else {</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;"><span class="Apple-tab-span" style="white-space:pre">     </span><<< "no coercion because type is incorrect..." >>>;</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; "><span style="font-size: 12px;">}</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;">---------</span></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 13px/normal Monaco; min-height: 17px; "><span style="font-size: 12px;"><br></span></p></div>
                <div><div><font face="Monaco" style="font-size: 12px;">Why?  Well, since this is all above board:</font></div><div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">SinOsc sin;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">Gain gain;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">sin @=> UGen one;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">gain @=> UGen two;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">one => two;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">one $ SinOsc @=> SinOsc sin2;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;">two $ Gain @=> Gain gain2;</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><<< sin2.isConnectedTo(gain2) >>>;  // 1, true</span></div><div style="font-family: Monaco; "><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">I could, for instance, build an object that connects arbitrary UGens together in a specified way while remaining ignorant what UGens those really are.  This could be a generic object that could operate on arbitrary UGens.  Later, I could then cast (coerce) them back into whatever class they were when they were originally instantiated.</span></div></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">At least, this is the kind of thing I wanted to do with this feature.  I kept asking myself, "what good is this object hierarchy if I can't use it to write less code?!"  Perhaps there's a way to accomplish the above without this feature--and, of course, better string methods would obviate the need for this--but you see what I mean.  You could do similar things with arrays of heterogenous objects.  Cast them all to Object type, iterate on them, move them around in an array, sort them by type, etc.  Then get them all back to their original type and use them as you like.  </span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">Of course, eventually, you have to decide whether you're okay with your code being useful to only you.  In the end, since the developers seem to be of the mind that this isn't the way you're supposed to do it (and I don't necessarily disagree--especially this way!) I opted to not maintain my own version of ChucK to support this feature.  But that's a personal preference; YMMV</span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">Anyway, I hope that this was helpful/interesting!  I'd love to see what you do with it, if you use it.</span></div><div><span style="font-size: 12px;"><br></span></div><div><span style="font-size: 12px;">Best,</span></div><div><span style="font-size: 12px;">Mike</span></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">-- </font></div><div><font face="Monaco" style="font-size: 12px;">Michael Clemow</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div><div><font face="Monaco" style="font-size: 12px;">http://michaelclemow.com</font></div><div><font face="Monaco" style="font-size: 12px;">http://abattoirprojects.com</font></div><div><font face="Monaco" style="font-size: 12px;"><br></font></div></div>
                 
                <p><font face="Monaco" style="font-size: 12px;">On Tuesday, December 25, 2012 at 1:59 PM, Wolfgang Gil wrote:</font></p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <font face="Monaco" style="font-size: 12px;"><span><div><div>Hey,<div><br></div><div>Mike, your suggestion sounds great. I look forward to hearing more about it.</div>
<div><br></div><div>Kassen, thanks for the info. My german name was given to me in Venezuela, where I was born. I have not german family whatsoever. I am half venezuelan, half spanish, currently leaving in NY. Here I met my fiancĂ©e, a japanese lady I have been living with for the last four years. I use more chopsticks than fork and knife these days</div>
<div><br></div><div><font color="#000000">C'est la vie ;)</font><br>
<br><div>On Mon, Dec 24, 2012 at 3:03 PM, mike clemow <span dir="ltr"><<a href="mailto:michaelclemow@gmail.com" target="_blank">michaelclemow@gmail.com</a>></span> wrote:<br><blockquote type="cite"><div>
Hey Wolfgang, Kas,<br>
<br>
So, a few years ago I wanted the same thing for intelligent casting<br>
purposes.  Instances of Object type respond to the method toString()<br>
as well as typeOf(), a stubbed out method in Object source code with<br>
no implementation.<br>
<br>
My solution was modify the implementation of toString() to only return<br>
the class name and inserted that into the stub for typeOf().<br>
<br>
After recompilation, I could call typeOf() on instances (or instances<br>
of subclasses of) Object and get a string representation of that<br>
object's type.<br>
<br>
I can be more specific about the change and the files involved when I<br>
get back to my home after the holidays (Wednesday).<br>
<br>
Hope this helps!  It's an easy change.<br>
<br>
-mike<br>
<br>
//--<br>
Sent from my Tracking Device.<br>
--//<br>
<div><div><br>
On Dec 24, 2012, at 6:40 AM, Kassen <<a href="mailto:signal.automatique@gmail.com">signal.automatique@gmail.com</a>> wrote:<br>
<br>
> On Sun, Dec 23, 2012 at 03:45:45PM -0500, Wolfgang Gil wrote:<br>
>> Hello chuckers<br>
>><br>
><br>
> Hey Wolfgang!<br>
><br>
>> I am looking for a reference to the 'string' object class in chuck. I am<br>
>> having a hard time trying to guess what methods are available for the<br>
>> class.<br>
><br>
> Sorry, but String is not a class, it is a primitive. Ok, it is a bit<br>
> unusual primitive that sometimes acts a bit differently from int,<br>
> float, dur, etc, but as far as I can remember those differences are<br>
> bugs. String should be a primitive with all of the advantages<br>
> (automatic instantiation) and all of the downsides (no member<br>
> functions) of those.<br>
><br>
> This is talking from the ChucK side, in the C++ source things might be<br>
> different; I never looked at that part of the source.<br>
><br>
><br>
>> I also recently came across with the StringTokenizer object but it seems to<br>
>> work only when the token is a white space. Is it possible to assign a<br>
>> different token to the object?<br>
><br>
> Sadly no, not that I know of. Do we need that?<br>
><br>
>> What gets printed is the object's type plus what I believe is a reference<br>
>> to memory that I am currently not interested in, separated by a colon (<br>
>> TriOsc:1001f36a0)<br>
>><br>
><br>
> Way cool! I've long wanted this. Could I suggest a way to get a array<br>
> of types in hierarchy? That way we could get something like;<br>
><br>
> ["Object", "UGen", "StkInstrument", "Sitar"] //it's all of those<br>
><br>
> or;<br>
><br>
> ["float"] //floats are clearly not objects, even is strings are weird.<br>
><br>
> That would be a great help when working with groups of objects that<br>
> have some things in common and not others. If, for examplle, we'd just<br>
> want a egg we could simply check whether the object is a "bird" and<br>
> thus would support .getEgg(), we might not be interested in whether it<br>
> has more detailed functions like .getBlueFeather() . In some cases<br>
> that might save a lot of checks and clean stuff up a lot. I don't like<br>
> big trees of IF's.<br>
><br>
> Currently that is mostly relevant for the StkInstrument series and the<br>
> Filter one, but I could see more sets like that and of course it would<br>
> make sense for our own class hierarchies.<br>
><br>
>><br>
>> Happy holidays!<br>
><br>
> You too! Don't let my modest proposals keep you away from this choice<br>
> reason to spend time with loved ones and food. There is probably some<br>
> rule against suggesting more work on Dec.24th to people with European<br>
> names. Sorry ;-)<br>
><br>
> Yours,<br>
> Kas.<br>
> _______________________________________________<br>
> chuck-users mailing list<br>
> <a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
> <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>

<p><a href="http://www.wolfganggil.com/about" target="_blank">http://www.wolfganggil.com</a></p>





</div>
</div><div><div>_______________________________________________</div><div>chuck-users mailing list</div><div><a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a></div><div><a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a></div></div></div></span>
                 
                 
                 
                 
                </font></blockquote>
                 
                <div>
                    <br>
                </div>