[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Warn about comparing quoted lists (etc) using `eq`
From: |
Mattias Engdegård |
Subject: |
Re: Warn about comparing quoted lists (etc) using `eq` |
Date: |
Thu, 15 Dec 2022 10:36:07 +0100 |
15 dec. 2022 kl. 05.17 skrev Juanma Barranquero <lekktu@gmail.com>:
> Note that your patch has a false positive with the empty string, which is
> optimized to be always the same object
That's only an implementation aspect that we give no guarantees about on the
Lisp language level, and in fact as you correctly observe:
> there are two, a unibyte one and a multibyte one
Precisely, and often there's no telling which one we compare against in (eq x
"") -- that expression may return t or nil when x is an empty string.
Thus it's definitely a well-motivated warning, toy examples like
> (let ((x "")) (eq x ""))
notwithstanding. We simply do not guarantee the identity of literal strings and
the empty string is no exception.
15 dec. 2022 kl. 07.34 skrev Dr. Arne Babenhauserheide <arne_bab@web.de>:
> I miss a suggestion, though: the warning as it is is not actionable. It
> would be great if it could say something along the lines of
>
> "... (arg 2). Consider using `equal'."
While this sounds like a useful suggestion on the surface, it's actually
slightly dangerous: blindly replacing `eq` with `equal` (and `memq` with
`member`, and so on) may very well break working code (that silently relied on
the condition not being true). It's also a poor remedy against pratfalls like
(memq x '(one 'two 'three))
which do occur. What we really want is to make a human look at the code, and
think.