;;; Helper function for the tail-recursive version of list-intersection.
;;; Argument A is the accumulator variable.
(defun list-intersection-aux (L1 L2 A)
"Compute the union of A and the intersection of lists L1 and L2."
(if (null L1)
A
(if (member (first L1) L2)
(list-intersection-aux (rest L1) L2 (cons (first L1) A))
(list-intersection-aux (rest L1) L2 A))))
;;; Actual implementation of tail-recursive list-intersection
(defun fast-list-intersection (L1 L2)
"Compute intersection of two lists L1 and L2 (tail-recursive version)."
(list-intersection-aux L1 L2 nil))