GNU bug report logs - #54639
26.1; (not (string-empty-p nil)) returns true

Previous Next

Package: emacs;

Reported by: Ernesto Alfonso <erjoalgo <at> gmail.com>

Date: Wed, 30 Mar 2022 16:21:01 UTC

Severity: minor

Tags: wontfix

Found in version 26.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Ernesto Alfonso <erjoalgo <at> gmail.com>
Cc: 54639 <at> debbugs.gnu.org
Subject: bug#54639: 26.1; (not (string-empty-p nil)) returns true
Date: Thu, 31 Mar 2022 13:26:56 +0200
Ernesto Alfonso <erjoalgo <at> gmail.com> writes:

> The expression (not (string-empty-p nil)) returns true. This is very
> conuterintuitive: nil is as "empty" a value as there is!

But nil isn't a string, and the function is only (meant to be) valid for
strings.  It "works" for symbols by accident.

> Some of the more reasonable alternatives I can think of in order of
> preference are:
>
> 1. (string-empty-p nil) simply returns t
> 2. (string-empty-p nil) raises a type error

We can't change how an established function works -- that would break
people's code.

> 3. subr-x.el provides a separate string-null-or-empty-p function

That would be just (zerop (length OBJECT)), which doesn't quite seem
worth having a function when the function name is longer than the
expression it replaces.  (And it would be misleading to have the
function name start with string- since it works on other things, too.)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 3 years and 51 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.