CL-USER> (defun make-counter (n)
(lambda ()
(incf n)))
MAKE-COUNTER
CL-USER> (defparameter c (make-counter 0))
C
CL-USER> (funcall c)
1
CL-USER> (funcall c)
2
CL-USER> (defparameter c2 (make-counter 0))
C2
CL-USER> (funcall c2)
1
(defun direct-product-2arg (lst1 lst2)
(let ((product ()))
(dolist (l1 lst1)
(dolist (l2 lst2)
(setf product (cons
(if (listp l2)
(cons l1 l2)
(list l1 l2)) product))))
(reverse product)))
(defun direct-product (&rest lsts)
(let ((lsts (reverse lsts)))
(nlet iter ((lsts (cdr lsts))
(product (car lsts)))
(if (null lsts)
product
(iter (cdr lsts) (direct-product-2arg (car lsts) product))))))