Why the following in emacs-lisp works as expected:
(set-difference '(1 2) '(1)) => (2)
But if strings used it doesn't:
(set-difference '("foo" "bar") '("foo")) => ("foo" "bar")
How do can I calculate set difference for sets of strings?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
It is for the same reason that:
(eql "foo" "foo") => nil
Along with the other
cl-lib sequence functions generally,
cl-set-difference) defaults to using
eql for its equality test, and therefore in your example none of the members of the first set are present in the second set.
You can tell it what to use for its equality test, however:
(set-difference '("foo" "bar") '("foo") :test #'equal) => ("bar")