[chuck-users] functions returning arrays

Colin Sullivan colinsul at gmail.com
Thu Feb 23 15:27:22 EST 2012


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.

If you used the same syntax to instead return an object's member variable
which is an array, I think it would work as expected.

Hope that helps.
----------
Colin



2012/2/23 David Ogborn <ogbornd at mcmaster.ca>

> Hi Chuckists,
>
> A question about arrays in Chuck: the manual briefly mentions "functions
> that have arrays as arguments or return type" but I can't seem to find an
> actual example of a function with an array as a return type.  Does anyone
> know if this works, or there is a way to make it work?
>
> If I call the function below, for instance, I get a "NullPointerException:
> (array access)" when I do anything with the result:
>
> fun float[] t(float x,float nn[]) {
>     float rr[];
>     for(0 => int n;n<nn.size();n++) {
>         nn[n] + x => rr[n];
>     }
>     return rr;
> }
>
> Yours truly,
> David
>
>  -------------------------------------------------------------------
> 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
>
>
>
>
>
>
>
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20120223/1b64db97/attachment.html>


More information about the chuck-users mailing list