cartesian-product
Die Funktion cartesian-product berechnet das kartesische Produkt zweier Listen. Das bedeutet, das jedes Element der ersten Liste mit jedem Element der zweiten Liste kombiniert wird.
> (cartesian-product (list 1 2) (list 3 4))
((1 3) (1 4) (2 3) (2 4))
Die Funktion basiert auf append, map-with und list:
(setq cartesian-product
(lambda (l1 l2)
(apply
append
(map-with
(lambda (e1)
(map-with
(lambda (e2) (list e1 e2))
l2))
l1))))
> (cartesian-product (list 1 2) (list 3 4))
((1 3) (1 4) (2 3) (2 4))
Die Funktion basiert auf append, map-with und list:
(setq cartesian-product
(lambda (l1 l2)
(apply
append
(map-with
(lambda (e1)
(map-with
(lambda (e2) (list e1 e2))
l2))
l1))))