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?
It is for the same reason that:
(eql "foo" "foo")
=> nil
Along with the other cl-lib
sequence functions generally, set-difference
(aka 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")