Returning an array value from a user-defined function.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Returning an array value from a user-defined function.

ved sharma
Hi all,

Here is an example macro and its output:

// start
array = newArray("a", "b", "c");
str1 = myFunction1(); print("str1 =  "+str1);
str2 = myFunction2(); print("str2 =  "+str2);

function myFunction1() {
        x=array[1];
        return x;
}
function myFunction2() {
        return array[1];
}
// end

output:
str1 =  b
str2 =  NaN

My question is, why can I not return an array value from a function without assigning it to a variable? Is this a bug or that is how return statement is supposed to work?

Thanks,

Ved

========================
Ved Sharma, Ph.D.
Albert Einstein College of Medicine
Bronx, New York

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Returning an array value from a user-defined function.

Rasband, Wayne (NIH/NIMH) [E]
On Jan 2, 2013, at 2:06 PM, Ved Sharma wrote:

> Hi all,
>
> Here is an example macro and its output:
>
> // start
> array = newArray("a", "b", "c");
> str1 = myFunction1(); print("str1 =  "+str1);
> str2 = myFunction2(); print("str2 =  "+str2);
>
> function myFunction1() {
> x=array[1];
> return x;
> }
> function myFunction2() {
> return array[1];
> }
> // end
>
> output:
> str1 =  b
> str2 =  NaN
>
> My question is, why can I not return an array value from a function without assigning it to a variable? Is this a bug or that is how return statement is supposed to work?

This bug is fixed in the 1.47i daily build. The problem only occurred with string array values.

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html