// file: pairs.rex // author: Robert Keller // purpose: defining function 'pairs' which creates the list of all pairs from // two lists // pairs(L, M), where L and M are lists, produces the list of all pairs, // the first element of the pair being from L and the second from M pairs(L, M) = mappend((X) => map((Y) => [X, Y], M), L); // How it works: Consider X to be a typical element of the first list L. // Then map((Y) => [X, Y], M)) creates a list of pairs, pairing each // element Y of M with X. The overall RHS then does this for each element // of L and appends the resulting lists together into a single list. test(pairs(["a", "b", "c", "d"], [1, 2, 3]), [["a", 1], ["a", 2], ["a", 3], ["b", 1], ["b", 2], ["b", 3], ["c", 1], ["c", 2], ["c", 3], ["d", 1], ["d", 2], ["d", 3]]);