I understand that __
is a list of one or more elements, and that ___
is 0 or more elements, but when I try this rule with 2 underscores I don't get the results I expect.
cartesianProduct[lis1_, lis2_] :=
ReplaceList[{lis1, lis2}, {{___, x_, ___}, {___, y_, ___}} :> {x, y}]
cartesianProduct[{a, b, c}, {x, y, z}]
(* {{a, x}, {a, y}, {a, z}, {b, x}, {b, y}, {b, z}, {c, x}, {c, y}, {c, z}} *)
I guess I do not understand the difference between _
, __
, and ___
. Which is the pattern for instructing Mathematica to do what I want?