Subject: bug#76055: 29.4; Doc of string-empty-p

From: Drew Adams <[email-masked]>
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).