[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding String to Beginning of Lines

From: Stefan Monnier
Subject: Re: Adding String to Beginning of Lines
Date: Tue, 10 Nov 2020 17:31:02 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> If you look at the definition:
> (defsubst string-empty-p (string)
>   "Check whether STRING is empty."
>   (string= string ""))

FWIW, I agree with Louis on this one: (equal string "") is shorter and
just as clear as (or even more clear than) `(string-empty-p string)`,
so I'm no fan of such a definition.

> | (defun rcd-string-empty-p (s)
> |   "Returns T if string is empty or NIL"
> |   (let ((s (if (null s) "" s)))
> |     (if (stringp s)
> |     (if (zerop (length s)) t nil))))
> That's more or less the same as
> (defun rcd-string-empty-p (s)
>   (or (null s) (and (stringp s) (zerop (length s)))))

BTW since (length nil) is zero, this can be reduced in most cases to
(zerop (length s)), the main difference being that the shorter
definition signals an error if passed an object that's neither an array
nor a proper list.

> But why handling an empty list specially, and not other empty sequences,
> like the empty vector?  That's what `seq-empty-p' in seq.el does, btw.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]