Skip to content

Instantly share code, notes, and snippets.

@sross
Created March 16, 2009 09:05
Show Gist options
  • Save sross/79799 to your computer and use it in GitHub Desktop.
Save sross/79799 to your computer and use it in GitHub Desktop.
(defun remove-all (elts list &key (key #'identity) (test #'eql))
"Removes all elements of ELTS from LIST. This is similar to set-difference with the exception
that the order of the elements in LIST is preserved."
(remove-if #'(lambda (elt) (member (funcall key elt) elts :test test)) list))
(defun all-same-order-p (list-of-lists &key (test #'eql))
"Returns true if the lists in LIST-OF-LISTS are all in the same order."
(flet ((same-order-p (list1 list2)
(let ((diff (set-exclusive-or list1 list2 :test test)))
(equal (remove-all diff list1 :test test)
(remove-all diff list2 :test test)))))
(loop for (first . rest) on list-of-lists
:always (loop for other in rest
:always (same-order-p first other)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment