Great - thanks! Yours truly, David On 2012-02-23, at 3:59 PM, mike clemow wrote:
Alternatively, you can implement this will the append operator:
fun float[] t(float x,float nn[]) {
// assign with zero length float rr[0];
for(0 => int n;n
<<< t(4.5, [7.,8.,9.])[2] >>>; // should print 13.5
http://michaelclemow.com http://semiotech.org
On Thu, Feb 23, 2012 at 3:56 PM, mike clemow
wrote: Yes, ditto to what Kassen said. (I'm too slow... ;)
fun float[] t(float x,float nn[]) {
float rr[nn.size()];
for(0 => int n;n
nn[n] + x => rr[n];
}
return rr;
}
<<< t(4.5, [7.,8.,9.])[2] >>>; // should print 13.5
http://michaelclemow.com http://semiotech.org
On Thu, Feb 23, 2012 at 3:45 PM, Kassen
wrote: On Thu, Feb 23, 2012 at 12:27:22PM -0800, Colin Sullivan wrote:
David,
I think the problem may be that you are returning an array that is local to your function and it is getting deallocated when the function returns.
That's what I thought too, and that certainly can happen. In that case a extra assignment (using @) can increase the reference count, tricking the simple CC. That's not "good form" just a workaround while some of that stuff is a bit dodgy.
That's not the issue here though, at least not the primary one. The primary issue here is that rr gets defined without a length and so apparently doesn't get initiated. Editing the relevant line to read;
float rr[nn.size()];
makes sure all floats are initiated and for my tests it works.
I think the issue is not with returning, the reported error is refering -I suspect- to the moment when we try to chuck the result of the addition to the array location, the error just isn't indicating that, obfuscating what went wrong.
I hope that helps (I also hope it's correct ;-) )
Yours, Kas.
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
------------------------------------------------------------------- Dr. David Ogborn, Assistant Professor Communication Studies & Multimedia Director, Cybernetic Orchestra & ESP Studio McMaster University, Hamilton, Canada ogbornd --at-- mcmaster.ca http://davidogborn.net http://twitter.com/ogbornd http://esp.mcmaster.ca (Cybernetic Orchestra) 1-905-525-9140 ext 27603