Return multiple values: Difference between revisions

J
(J)
Line 18:
 
Its stack effect declares that ''*/'' always returns 2 values. To return a variable number of values, a word must bundle those values into a [[sequence]] (perhaps an array or vector). For example, ''factors'' (defined in ''math.primes.factors'' and demonstrated at [[Prime decomposition#Factor]]) returns a sequence of prime factors.
 
=={{header|J}}==
To return multiple values in J, you return an array which contains multiple values. Since the only data type in J is array, this is sort of like asking how to return only one value in another language.
 
<lang j> 1 2+3 4
4 6</lang>
 
=={{header|Pike}}==
Line 30 ⟶ 36:
[int z, int w] = addsub(5,4);
</lang>
 
=={{header|Ruby}}==
Every function returns one value. The conventional way to return multiple values is to bundle them into an Array.
6,962

edits