Login  Register

Re: Passing arrays to functions without declaring an array variable first

Posted by Herbie on Nov 23, 2019; 6:18pm
URL: http://imagej.273.s1.nabble.com/Passing-arrays-to-functions-without-declaring-an-array-variable-first-tp5022700p5022701.html

Good day Stein,

in your second example there is no name of the array but there need to be
one because the array is "in a certain sense returned" after the execution
of the function. In your second example there is no variable for the
"returned" array.

HTH

Herbie

::::::::::::::::::::::::::::::::::::::::::

Assuming a macro function accepting an array as a parameter:

function printArray(a) {
                print("");
                for (i=0; i<a.length; i++)
                               print(i+&quot;: &quot;+a[i]);
}

What is the reason this works:

arr = newArray(&quot;cat&quot;, &quot;dog&quot;, &quot;mouse&quot;,
&quot;rabbit&quot;);
printArray(arr);

But not this:

printArray(newArray(&quot;cat&quot;, &quot;dog&quot;, &quot;mouse&quot;,
&quot;rabbit&quot;));

?

Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
&lt;/quote>




--
Sent from: http://imagej.1557.x6.nabble.com/

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