GNU bug report logs - #76055
29.4; Doc of string-empty-p

Previous Next

Package: emacs;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Tue, 4 Feb 2025 20:29:01 UTC

Severity: minor

Tags: wontfix

Found in version 29.4

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 76055 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: "Alfred M. Szmidt" <ams <at> gnu.org>
Cc: "76055 <at> debbugs.gnu.org" <76055 <at> debbugs.gnu.org>,
 "eliz <at> gnu.org" <eliz <at> gnu.org>
Subject: RE: [External] : Re: bug#76055: 29.4; Doc of string-empty-p
Date: Wed, 5 Feb 2025 23:28:40 +0000
>    A function such as `string-empty-p' is a prime
>    candidate for checking and adding such mention.
> 
>    Its name (and its current doc string) provides
>    no clue that it handles a symbol argument as
>    if you were passing (symbol-name <the symbol>).
> 
> Why should it?  Lisp is a dynamic language, and 
> predicates generally accept anything.  If anything,
> if the notion is that string-empty-p should _reject_ 
> anything but strings, it should be an assert!
> (Not saying that should be the case ...)

This is essentially a type predicate (per its
name, if nothing else): test whether the arg is
an empty string.

Of _course_ you can pass it a value of any type.
But what should its behavior be for a non-string
arg?

There was a choice made of whether to return nil
for an arbitrary non-string or to raise an error.
Emacs chose the latter, and I have _no problem_
with that.

(string-empty-p [1 2])       ; -> error
(string-empty-p 42)          ; -> error
(string-empty-p (cons 1 2))  ; -> error
(string-empty-p nil)         ; -> error

But if the non-string is a symbol then we have
a different story:

(string-empty-p "cat")       ; -> nil
(string-empty-p 'cat)        ; -> nil

(string-empty-p "")          ; -> t
(string-empty-p (intern "")) ; -> t

The handling of a symbol arg isn't something
someone would expect, just by looking at the
function name and reading the doc.

It raises an error for a non-string argument,
showing that it is, indeed, an empty-string
type predicate...

...EXCEPT for a non-string argument that's a
symbol.  If the `symbol-name' of the symbol
is "" then it returns t.  If the name is "x"
it returns nil.

That's what's missing.  It's not _at all_
obvious it would do this - neither from its
name nor from its doc.  It presents itself
as just an empty-string type predicate.

Just what is this function?  It's simply a
`string=' test for "".  And lo and behold,
the doc string of `string=' tells us loud
and clear:

  Symbols are also allowed; their print
  names are used instead.

Thank you very much, Emacs doc!  I have no
problem with this choice of behavior.  And
the doc is nice enough to make the behavior
clear.

The doc of `string-empty-p' should obviously
do the same - for the same reason: because
this exceptional non-string behavior is not
obvious, and the predicate's name and doc
suggests a different behavior (so far).




This bug report was last modified 131 days ago.

Previous Next


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