Torsten Anders wrote:
/** %% Collects in Zs the result of applying the binary function Fn on
all possible combinations of Xs and Ys. The order in Zs is [{Fn X1 Y1}
{Fn X1 Y2} ... {Fn X1 Yn} {Fn X2 Y1} ... {Fn Xn Yn}].
%% */
proc {MapCartesianProduct Xs Ys Fn Zs}
LYs = {Length Ys}
ZsAux = {MakeTuple unit {Length Xs}* LYs}
in
{List.forAllInd Xs
proc {$ I X}
{List.forAllInd Ys
proc {$ J Y}
ZsAux.(((I-1)*LYs)+J) = {Fn X Y}
end}
end}
Zs = {Record.toList ZsAux}
end
Of course, this is a matter of taste. But I think MapCartesianProduct
looks more readable with collect:
fun {MapCartesianProduct Xs Ys Fn}
for X in Xs collect:C do
for Y in Ys do {C {Fn X Y}} end
end
end
Luis
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users