(use-modules (srfi srfi-1))
(define (cartesian-product . sets)
(cond
((null? sets) '(()))
(else
(let ((rest (apply cartesian-product (cdr sets))))
(append-map
(lambda (x)
(map (lambda (r) (cons x r)) rest))
(car sets))))))