[chuck-users] determining the type of an Object in code

mike clemow gelfmuse at gmail.com
Sun Sep 7 15:59:05 EDT 2008


I was wondering whether that would work!

Like this works, for instance:

SinOsc s;
s @=> Object o;
o $ SinOsc @=> SinOsc osc;
500 => osc.freq;
osc => dac;

1::second => now;

It's the same principle, anyway.

cheers,
mike

On Sun, Sep 7, 2008 at 3:47 PM, Michael Heuer <heuermh at gmail.com> wrote:
> Kassen wrote:
>>
>> 2008/9/5 Michael Heuer <heuermh at gmail.com>
>>>
>>> For what it's worth, I have updated my List APIs to use resizeable
>>> arrays and posted them to the forum at
>>>
>>> http://electro-music.com/forum/viewtopic.php?t=21725
>>>
>>> Each file contains some "unit tests" so you might look to those for
>>> examples on how to use the list classes.
>>
>> Michael,
>>
>> Do I understand correctly that the top file, the one that deals purely with
>> Object's, works but is mainly of interest from a academic perspective? I
>> like what you are doing but it's not clear to me how we would get the
>> results out at the other end without being able to tell anything about the
>> type, beyond it being a "Object" and getting it's memory location.
>>
>> Is this purely meant as a abstract demonstration?
>>
>> Yours,
>> Kas,
>
> Hello Kas,
>
> ChucK has a cast operator, so you should be able to cast the result of
> List.get(int), Iterator.next(), or the object parameter in a
> forEach(UnaryPredicate) to what you expect the Object to be.  This
> works:
>
> ArrayList list;
> Qux qux0;
> Qux qux1;
> Qux qux2;
>
> list.add(qux0);
> list.add(qux1);
> list.add(qux2);
>
> list.get(0) $ Qux @=> Qux qux;
> <<<qux.garply()>>>;
>
> $ chuck --silent list_of_qux.ck
> 42 :(int)
>
>   michael
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>



-- 
http://semiotech.org
http://semiotech.org/michael


More information about the chuck-users mailing list