[chuck-users] quiting chuck from chuck and saving reference to function

altern altern2 at gmail.com
Wed Nov 8 22:58:13 EST 2006


Spencer Salazar wrote:
> On Nov 8, 2006, at 10:39 AM, altern wrote:
> 
>> The only difference between all those shreds is the action the need to
>> perform so i wanted to declare a variable for each and pass it as a
>> reference when sporking the shread.
>>
>> [...]
>>
>> But this is impossible then.
> 
> Au contraire!  As Ge mentioned, you can achieve the same result using  
> polymorphic inheritance.  Practically, this would mean defining an  
> abstract base class like this:
> 
> class OscAction
> {
>      fun void action() { }
> }
> 
> and then, for each actual action, define a corresponding subclass  
> that "overloads" the action function:
> 
> class QuitAction extends OscAction
> {
>      fun void action() { Machine.crash(); }
> }
> 
> class DoSomethingElseAction extends OscAction
> {
>      fun void action() { /* do something else */ }
> }
> 
> Define oscshred like this:
> fun void oscshred( OscEvent e, OscAction a )
> 
> call
> spork ~ oscshred( quit_osc, new QuitAction );
> 
> to start up the quit listener and then call a.action() to actually  
> execute the action when you receive the appropriate OSC message.
> 
> hope this helps/makes sense.


sure! now i understand.
thanks!



More information about the chuck-users mailing list