Return multiple values: Difference between revisions
Content added Content deleted
(J) |
|||
Line 18: | 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. |
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}}== |
=={{header|Pike}}== |
||
Line 30: | Line 36: | ||
[int z, int w] = addsub(5,4); |
[int z, int w] = addsub(5,4); |
||
</lang> |
</lang> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Every function returns one value. The conventional way to return multiple values is to bundle them into an Array. |
Every function returns one value. The conventional way to return multiple values is to bundle them into an Array. |