Subject: Re: bug#34852: 26.1; seq-intersection ignores nil as element

From: "Miguel V. S. Frasson" <[email-masked]>
Date: Thu, 14 Mar 2019 09:52:06 -0300

Hi.
In https://lists.gnu.org/archive/html/emacs-devel/2016-07/msg01256.html
it is mentioned that:

>    I believe `seq-contains' was introduced for convenience:
>    it is used elsewhere in seq.el and map.el.

so there may be problems in map.el as well if it is used as a
predicate there, or even in more files.

Miguel.

Em qui, 14 de mar de 2019 às 09:22, Basil L. Contovounesios
<[email-masked]> escreveu:
>
>
> "Miguel V. S. Frasson" <[email-masked]> writes:
>
> > seq-intersection skips nil as common element, so returns wrong result.
> >
> > Reproducing from emacs -Q:
> >
> > In *scratch* buffer, eval the expressions
> >
> > (progn
> >   (require 'seq)
> >   (seq-intersection '(1 2 nil) '(1 nil) 'eq))
> >
> > -> (1)
> >
> > (seq-intersection '(1 2 nil) '(1 nil) 'equal)
> >
> > -> (1)
> >
> > Expected result in both cases: (1 nil)
>
> This is actually due to seq-contains returning the element found, rather
> than a boolean indicating whether the element was found:
>
> (seq-contains '(nil) nil) ; => nil
>
> The nature of seq-contains as a predicate-ish has been discussed in the
> past[1], and Stefan recently fixed a similar problem with
> map-contains-key[2].
>
> [1]: https://lists.gnu.org/archive/html/emacs-devel/2016-07/msg01256.html
> [2]: * lisp/emacs-lisp/map.el: Make the functions generic
>   2018-12-11 17:54:13 -0500
>   https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=1691a51094d35ac4b2c311fa407c6b77eea7a105
>
> One solution is to leave seq-contains as it is, and switch to using
> seq-position (or some new predicate) as a predicate instead.  Another is
> to make seq-contains return a boolean instead of the needle found, which
> would be a backward-incompatible change similar to that for
> map-contains-key.  I attach a patch for each of these respective
> solutions; WDYT?
>
> --
> Basil

-- 
Miguel Vinicius Santini Frasson
[email-masked]