如果您不想使用库,可以使用以下代码执行相同的操作,并可以使用任意数量的列表:
(defun combinations (&rest lists) (if (endp lists) (list nil) (mapcan (lambda (inner-val) (mapcar (lambda (outer-val) (cons outer-val inner-val)) (car lists))) (apply #'combinations (cdr lists)))))[2]> (combinations '(1 2))((1) (2))[3]> (combinations '(1 2) '(3 4))((1 3) (2 3) (1 4) (2 4))[4]> (combinations '(1 2) '(3 4) '(5 6))((1 3 5) (2 3 5) (1 4 5) (2 4 5) (1 3 6) (2 3 6) (1 4 6) (2 4 6))



