Oh heck, let's just cut to the chase and hack a Chuck meta-object protocol...<div><br></div><div>(oops, sorry.  that just slipped out.  ;)</div><div><br></div><div>Honestly, I've run into this a lot in the past and I'm familiar with this frustration.  I even hacked my own version of chuck in which each object responded to a .typeOf(); message that returned a string representation (I know, it's ugly) of it's class name.  I used this to make do smart casting, which I admit is still a huge compromise.  I still think that each class name (reserved word) should be able to represent itself.  Something to the tune of:</div>
<div><br></div><div>if( myUgen.typeOf() == SinOsc ) {    // seems reasonable, right?</div><div>    myUgen $ SinOsc => SinOsc s;</div><div>}</div><div><br></div><div>But even then, short of wrapping all UGens in another class in order to gain more control from these sorts of operations, we still have to do the cast ourselves, which would make some sense if it was ever reasonable to cast a SinOsc as anything other than a UGen, but that would be...  frankly, bizarre.  </div>
<div><br></div><div>For this reason, I think that the Chuck language should take care of this situation for us (at least where UGens are concerned--we can build).  If we are forced to cast because Chuck is strictly typed, so be it.  But then we should be able to ask any object what it really is an instance of.  There are good reasons why Chuck is strictly typed, however, IMHO, this is an unnecessary restriction.  Even Java can do this--and I rarely stick my neck out for Java.</div>
<div><br></div><div>Anyway, I've been on this soapbox before, so I'll stop my drivel.</div><div><br></div><div>Mike</div><div><br></div><div><br></div><div><br><br><div class="gmail_quote">On Mon, Nov 8, 2010 at 2:50 PM, Michael Heuer <span dir="ltr"><<a href="mailto:heuermh@gmail.com">heuermh@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Kassen:<br>
<div><div></div><div class="h5">> Andy;<br>
>><br>
>> I'm not sure that's true. I just tried this:<br>
>><br>
><br>
> You are right. I doubted for a moment because of the array and how arrays<br>
> tend to muck with the type system but this fails too;<br>
> JCRev foo;<br>
> .1 => ((foo $ UGen) $ Chorus).mix;<br>
><br>
>><br>
>> The "mix" method won't have a common location in the vtable. You might<br>
>> get lucky casting a JCRev to a PitShift since "mix" is the first<br>
>> method for both of them, but I certainly wouldn't count on that to<br>
>> always work.<br>
><br>
> Indeed! Turns out we just got lucky a lot of times. It does work for the<br>
> STKInstruments and the convenience filters. I seem to remember you can also<br>
> have it work for anything that has a .freq() but maybe there too we just got<br>
> lucky so far.<br>
> That's a bit disappointing; it was a nice trick while it lasted. I suppose<br>
> it still is for those places where you can get away with it. I think I<br>
> talked about this before, but I'd like any object to have a .type() that<br>
> would return a array like this; ["Object", "UGen", "Filter, "LPF"]. The VM<br>
> has all of that data, we just can't get to it.<br>
<br>
</div></div>There is some relevant code for the cast operator, chuck_type.cpp,<br>
line 2488 and related.  It looks rather incomplete to me, and maybe<br>
this is the most telling<br>
<br>
line 2530:<br>
    // TODO: dynamic type checking<br>
<br>
If anyone can hack together an instanceof operator from this, the<br>
effort would be greatly appreciated.  :)<br>
<font color="#888888"><br>
   michael<br>
</font><div><div></div><div class="h5">_______________________________________________<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></blockquote></div><br><br clear="all"><br>-- <br><a href="http://michaelclemow.com">http://michaelclemow.com</a><br><a href="http://semiotech.org">http://semiotech.org</a><br><br>
</div>