The remove-duplicates function should receive (:key #'car ) argument, since it is intended to remove the same variable being bound. Patch attached.
By the way, I was thinking if it could be possible to bind some local variables (since not all implementations support closures).
(defvar *closure-value-table* (make-hash-table :test #'eq :size 10))
(defmacro make-thread-with-closure ((&rest vars) function &rest make-thread-args) (let ((vars (mapcar #'(lambda (var) (if (atom var) (list var) var)) vars)) (table-code (gensym))) `(progn (setf (gethash ',table-code *closure-value-table*) (list ,@(mapcar #'second vars))) (make-thread (lambda () (destructuring-bind ,(mapcar #'car vars) (gethash ',table-code *closure-value-table*) (remhash ',table-code *closure-value-table*) (funcall ,function))) ,@make-thread-args))))
cl-user> (make-thread-with-closure ((a 1) (b 2)) (lambda () (+ a b))) #<sb-thread:thread "Anonymous" running {1005745721}> cl-user> * #<sb-thread:thread "Anonymous" finished values: 3 {1005745721}> cl-user>
Maybe a lock is needed to access the hash-table since not all implementations support concurrent table access, but that is the general idea.
Gustavo.