Yuri Khan wrote:
> Maybe
>
> (cl-set-difference '("0" "a" "b" "c" "d")
> '("a" "b")
> :test 'string=)
>
> ?
Excellent, thanks!
You got the right idea, "sublist" as in the
math unordered set sense - and not "set" as in
the serpent god of the paleo-pharaohs, here!
And items in the sublist that do not appear
should be dropped, as happens.
Should the test function be hash-quoted?
Only strange thing is the order is reversed,
except for the empty list as sublist! I just
said it was in the unordered sense, however one
might just as well keep the order, especially
since even/particularly in the math unordered
set sense, {1 2 3} = {3 2 1}, right? So it
should work both ways; and it might be useful
for example if you have a list of functions,
(f1 f2 f3 f4), and it is a priority list so if
f1 is defined, run it, if not, try/run f2,
etc., here, if the user dislikes f2 and f3, but
have them defined for other purposes, s/he can
remove them from the list without changing
the priority!
However how is that supposed to be done?
What about
(defun drop-sublist (l sl)
(if sl
(reverse (cl-set-difference l sl :test #'string-equal))
l))
;; (drop-sublist '("0" "a" "b" "c" "d") '("a" "b" "x"))
;; (drop-sublist '("0" "a" "b" "c" "d") '(x))
;; (drop-sublist '("0" "a" "b" "c" "d") '())
?
It sort of goes against grain to reverse to
*preserve* the order, but I suppose this is
what makes programming an engineering and not
a scientific endeavor...