Cartesian product of two or more lists: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Minor tidy)
(→‎{{header|langur}}: updated to use mapX() instead of X())
Line 2,974: Line 2,974:
</pre>
</pre>
=={{header|langur}}==
=={{header|langur}}==
{{works with|langur|0.8.11}}
We could use mapX() to map each set of values to a function, but this assignment only requires an array of arrays, so we use the X() function.
<syntaxhighlight lang="langur">writeln mapX(f(... .x) .x, [1, 2], [3, 4]) == [[1, 3], [1, 4], [2, 3], [2, 4]]

writeln mapX(f(... .x) .x, [3, 4], [1, 2]) == [[3, 1], [3, 2], [4, 1], [4, 2]]
{{works with|langur|0.8.3}}
<syntaxhighlight lang="langur">writeln X([1, 2], [3, 4]) == [[1, 3], [1, 4], [2, 3], [2, 4]]
writeln mapX(f(... .x) .x, [1, 2], []) == []
writeln X([3, 4], [1, 2]) == [[3, 1], [3, 2], [4, 1], [4, 2]]
writeln mapX(f(... .x) .x, [], [1, 2]) == []
writeln X([1, 2], []) == []
writeln X([], [1, 2]) == []
writeln()
writeln()


writeln X [1776, 1789], [7, 12], [4, 14, 23], [0, 1]
writeln mapX f(... .x) .x, [1776, 1789], [7, 12], [4, 14, 23], [0, 1]
writeln()
writeln()


writeln X [1, 2, 3], [30], [500, 100]
writeln mapX f(... .x) .x, [1, 2, 3], [30], [500, 100]
writeln()
writeln()


writeln X [1, 2, 3], [], [500, 100]
writeln mapX f(... .x) .x, [1, 2, 3], [], [500, 100]
writeln()</syntaxhighlight>
writeln()</syntaxhighlight>


Line 3,004: Line 3,002:
[]
[]
</pre>
</pre>

=={{header|Lua}}==
=={{header|Lua}}==
=== Functional ===
=== Functional ===