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

altern altern2 at gmail.com
Wed Nov 8 11:39:04 EST 2006

hi all

first of all thanks for the answers

Kassen wrote:
>     here i am again with a couple of questions :
>     A : is it possible to quit Chuck from Chuck? I need to quit chuck
>     when a
>     certain osc message arrives, and i was wondering if there is a command
>     to do this.
> How about using the comand (forgot it's name) to call something from the 
> OS and use it to call "chuck --kill"?
>     B: can i store references to functions in variables? similar to the
>     python:
>     def myfunc():
>             dowhatever
>     myvar = myfunc
>     myvar()
> I don't think so, since they aren't objects they can't be asigned (to my 
> knowledge). As a work around you could write a function that would have 
> the new name and just pass on the variables to the older one? I don't 
> realy understand the purpose from your example though.

I explain below my problem and why i wanted to assign a function to a 
i am trying to understand how to structure a complex OSC communication 
with several incoming message types.
Because i am new to ChucK i am still trying to understand the chuckian 
way of doing things, and my paradigm at the moment is python which is 
the language i use all the time.
I am using something like this to deal with the OSC at the moment but 
which few more message types
// two type of incoming messages in this example -> /pitch and /quit
1 => float pitch;
OscRecv recv;
9000 => recv.port;
recv.event("/pitch, f") @=> OscEvent pitch_osc;
recv.event("/quit, i") @=> OscEvent quit_osc;
spork ~ oscshred(pitch_osc, "pitch");
spork ~ oscshred(quit_osc, "quit");
fun void oscshred(OscEvent e, string s){
		e => now;
		while(e.nextMsg() != 0){
			if (s=="quit"){
				<<<"quiting chuck here">>>;
			if (s=="pitch"){
				e.getFloat() => pitch; // put incoming value into var
				<<<"pitch", pitch>>>;

//main loop
while ( true ){
	0.2::second => now;

So for each message i spork a shred with the event and a string as id, 
then i check for the string id when a message arrives and trigger some 
action. It looks stupid to me to have to check for the string value in 
all of them. Another issue that sounds weird as well is that I need to 
have few more messages (around 40).

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. Something like
fun quit(){Machine.crash();}
spork ~ oscshred(quit_osc, quit); //passing ref to function
fun void oscshred(OscEvent e, func f){
		e => now;
		while(e.nextMsg() != 0){
			f(); //triggering function, different for each


But this is impossible then.

Couple of more questions, this time about OSC.
is it possible to receive arrays?
is it possible to check for the beginning of the address and redirect 
the rest? (like in PD with the OSCroute object, it checks for first part 
of address, in /sampler6/pitch would check for /sampler6 and if this 
matches then it sends the rest somewhere else.

Sorry if the questions are stupid i am just trying to get my head around 



> Hope that was of some help,
> Kas.
> ------------------------------------------------------------------------
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

More information about the chuck-users mailing list