(defun boolean-values (n &aux (result '((t) (nil))) (new-result '())) (dotimes (i (1- n) result) (dolist (thing result) (push (cons nil thing) new-result) (push (cons t thing) new-result)) (setf result new-result new-result '()))) CL-USER> (boolean-values 3) ((T NIL T) (NIL NIL T) (T T T) (NIL T T) (T NIL NIL) (NIL NIL NIL) (T T NIL) (NIL T NIL))