Loop over multiple arrays simultaneously: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Clarified type of first example, applied standard formatter.) |
imported>Maxima enthusiast No edit summary |
||
Line 2,955: | Line 2,955: | ||
<syntaxhighlight lang="mathematica">MapThread[Print, {{"a", "b", "c"}, {"A", "B", "C"}, {1, 2, 3}}];</syntaxhighlight> |
<syntaxhighlight lang="mathematica">MapThread[Print, {{"a", "b", "c"}, {"A", "B", "C"}, {1, 2, 3}}];</syntaxhighlight> |
||
All arguments must be lists of the same length. |
All arguments must be lists of the same length. |
||
=={{header|Maxima}}== |
|||
<syntaxhighlight lang="maxima"> |
|||
/* Function that loops over multiple arrays simultaneously depending on the list with less length */ |
|||
lomas(L):=block( |
|||
minlen:lmin(map(length,L)), |
|||
makelist(makelist(L[i][j],i,1,length(L)),j,1,minlen))$ |
|||
/* Test case */ |
|||
lst:[[a,b,c],[A,B,C],[1,2,3]]$ |
|||
lomas(lst); |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
[[a,A,1],[b,B,2],[c,C,3]] |
|||
</pre> |
|||
=={{header|Mercury}}== |
=={{header|Mercury}}== |