Only recently I've discovered that ListDifference subfunction isn't always applicable, so I am refering to this example found on Lee Mac's site :
;;-------------------=={ List Difference }==------------------;;
;; ;;
;; Returns items appearing exclusively in one list but not ;;
;; another, i.e. the relative complement: l1 \ l2 ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; l1,l2 - lists for which to return the difference ;;
;;------------------------------------------------------------;;
;; Returns: List of items appearing exclusively in list l1 ;;
;;------------------------------------------------------------;;
(defun LM:ListDifference
( l1 l2
) )
For instance if lists contain the same elements, this will give wrong result :
(LM:ListDifference '(0 1 1 2 2 2 3 3 3 3 4 4 4 4 4) '(0 1 2 3 4))
will return : nil
So I've decided to share my subfunction for this linear subtraction of lists with the same elements :
(defun prelst
( lst el
/ f
) )
)
(defun diff
( l1 l2
/ el
) )
And in my case, result is :
(diff '(0 1 1 2 2 2 3 3 3 3 4 4 4 4 4) '(0 1 2 3 4))
(1 2 2 3 3 3 4 4 4 4)
You will say just what it should return, like you removed exactly those elements of second list from first list...
I hope someone will use my discovery...
Hope that Lee won't be upset - his subfunctions are also very useful, and in many cases I used just above posted example from Lee's site, but now I think this is also at least good to mention...
Regards, M.R.