![](https://secure.gravatar.com/avatar/8a1ca9f288a1644e9e07d7f11d2f494c.jpg?s=120&d=mm&r=g)
Hello list, Couldn't find this one in the manual. Where do sporked funcitons return to? How do I get the return value of a spoked function? fun int addThree( int i ) { return i + 3; } spork ~ addThree( 2 ); ...5? cheers, mike -- http://semiotech.org
![](https://secure.gravatar.com/avatar/fa5a8de5c6e6c5838fc8106b390c7a6d.jpg?s=120&d=mm&r=g)
2008/6/6 mike clemow
Hello list,
Hey, mike!
Couldn't find this one in the manual. Where do sporked funcitons return to? How do I get the return value of a spoked function?
they don't and you won't, I fear..... (or shred-heaven, depending on your persuasion) Normal functions run inside of a shred and can return a value for the rest of the shred to work with. Sporked functions, on the other hand, run paralel to the sporking shred, in their own shred. As the originating shred doesn't wait for them to finish it makes no sense for them to return anything. Because of this you can only spork functions of return-type "void". You can still, BTW, advance time within a normal function if you'd like. On the other hand; you don't need to advance time in sporked functions as such, it's just that sporking only makes sense if you also advance time in that function/shred. Because of this I'm not really sure what you need return values from sporked functions for but if your sporked functions need to comunicate to the other shreds on what they've done events may suit your needs? Hope that clarifies. Yours, Kas.
![](https://secure.gravatar.com/avatar/8a1ca9f288a1644e9e07d7f11d2f494c.jpg?s=120&d=mm&r=g)
Yeah, that's what I figured. It's okay, it was actually a dumb idea
anyway. I'm creating micro-structures of wavelet grains by sporking a
function that sequences the sporking of functions that run the
wavelets. Both functions need to advance time and must be sporked (so
they can be simultaneous). i wanted them to return a duration equal
to the length that they ran. But if i do my job right i will either
a) know ahead of time or, b) not care.
Thanks!
;-)
-mike
On Fri, Jun 6, 2008 at 2:34 AM, Kassen
2008/6/6 mike clemow
: Hello list,
Hey, mike!
Couldn't find this one in the manual. Where do sporked funcitons return to? How do I get the return value of a spoked function?
they don't and you won't, I fear..... (or shred-heaven, depending on your persuasion)
Normal functions run inside of a shred and can return a value for the rest of the shred to work with. Sporked functions, on the other hand, run paralel to the sporking shred, in their own shred. As the originating shred doesn't wait for them to finish it makes no sense for them to return anything. Because of this you can only spork functions of return-type "void".
You can still, BTW, advance time within a normal function if you'd like. On the other hand; you don't need to advance time in sporked functions as such, it's just that sporking only makes sense if you also advance time in that function/shred.
Because of this I'm not really sure what you need return values from sporked functions for but if your sporked functions need to comunicate to the other shreds on what they've done events may suit your needs?
Hope that clarifies. Yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
![](https://secure.gravatar.com/avatar/fa5a8de5c6e6c5838fc8106b390c7a6d.jpg?s=120&d=mm&r=g)
2008/6/6 mike clemow
Yeah, that's what I figured. It's okay, it was actually a dumb idea anyway. I'm creating micro-structures of wavelet grains by sporking a function that sequences the sporking of functions that run the wavelets. Both functions need to advance time and must be sporked (so they can be simultaneous). i wanted them to return a duration equal to the length that they ran. But if i do my job right i will either a) know ahead of time or, b) not care.
You got it; this sounds like a perfectly healthy attitude towards sporking and shred-infrastructure. I wondered for a while why definitions for shreds to be sporked were functions as well because as you now see functions and shreds are quite different on some level. The nice thing is though that with them also being functions we can choose whether we want the function to run paralel or serial. That's quite nice and it may make sense on a musical level as well. In a way they are like straight repetition as compared to a canon. Good question. Well, I *hope* it's a good question because a few months back I experimented with the same thing and tried to think of a use for sporked shreds returning data. In the end I couldn't but it was a interesting thought experiment and led to fun tests. Cheers, Kas.
![](https://secure.gravatar.com/avatar/e65fbeab5934976843e19fe191c44edd.jpg?s=120&d=mm&r=g)
Hi all,
Couldn't find this one in the manual. Where do sporked funcitons
return to? How do I get the return value of a spoked function?
they don't and you won't, I fear..... (or shred-heaven, depending on your persuasion)
Shred-heaven would have been my assumption, but it doesn't appear to be the case, and it does make a difference..... at the moment, it appears that if you run // <chuck> int addThree(int i){ <<< "adding three..." >>>; return i + 3; } <<< "about to spork..." >>>; spork ~ addThree(2); <<< "sporked" >>>; // </chuck> then you get neither an error, nor the message "adding three..."; but you do get the other two messages. So, say the main purpose of the function was to do a load of other stuff, and the return value was just there for conveniance, or to return any error code perhaps (and you didn't expect to be able to read it in the context of sporking the function)... you get some rather unexpected behaviour, it seems to me. Regards, Peter
![](https://secure.gravatar.com/avatar/e65fbeab5934976843e19fe191c44edd.jpg?s=120&d=mm&r=g)
oops... missed a 'fun'
should be "fun int"...
On Sat, Jun 7, 2008 at 1:04 PM, Peter Todd
Hi all,
Couldn't find this one in the manual. Where do sporked funcitons
return to? How do I get the return value of a spoked function?
they don't and you won't, I fear..... (or shred-heaven, depending on your persuasion)
Shred-heaven would have been my assumption, but it doesn't appear to be the case, and it does make a difference..... at the moment, it appears that if you run
// <chuck> int addThree(int i){ <<< "adding three..." >>>; return i + 3; }
<<< "about to spork..." >>>; spork ~ addThree(2); <<< "sporked" >>>; // </chuck>
then you get neither an error, nor the message "adding three..."; but you do get the other two messages. So, say the main purpose of the function was to do a load of other stuff, and the return value was just there for conveniance, or to return any error code perhaps (and you didn't expect to be able to read it in the context of sporking the function)... you get some rather unexpected behaviour, it seems to me.
Regards, Peter
![](https://secure.gravatar.com/avatar/064d9ee85e24f87d406cf9bcc7419d05.jpg?s=120&d=mm&r=g)
Hello, On Jun 7, 2008, at 5:04 AM, Peter Todd wrote:
Hi all,
Couldn't find this one in the manual. Where do sporked funcitons return to? How do I get the return value of a spoked function?
they don't and you won't, I fear..... (or shred-heaven, depending on your persuasion)
Shred-heaven would have been my assumption, but it doesn't appear to be the case, and it does make a difference..... at the moment, it appears that if you run
// <chuck> int addThree(int i){ <<< "adding three..." >>>; return i + 3; }
<<< "about to spork..." >>>; spork ~ addThree(2); <<< "sporked" >>>; // </chuck>
then you get neither an error, nor the message "adding three..."; but you do get the other two messages. So, say the main purpose of the function was to do a load of other stuff, and the return value was just there for conveniance, or to return any error code perhaps (and you didn't expect to be able to read it in the context of sporking the function)... you get some rather unexpected behaviour, it seems to me.
This behavior does make some sense. When a shred exits, it kills any shreds it sporked. Additionally, when a shred is sporked, it is not scheduled to run immediately, but rather added to a FIFO queue of shreds to run after the current shred yield()'s or x => now;'s. The potentially thorny part is that, when a shred exits, the "exit" operation occurs before any shreds on the run queue are scheduled to execute. Thus, any recently sporked shreds are killed before running at all. So, for what its worth, the behavior of all three messages printing can be achieved by adding a me.yield(); at the end of the program above. me.yield() effectively exhausts the run queue before returning. spencer
Regards, Peter _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (4)
-
Kassen
-
mike clemow
-
Peter Todd
-
Spencer Salazar