emacs-devel
[Top][All Lists]
Advanced

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

Re: Predicate for true lists


From: Basil L. Contovounesios
Subject: Re: Predicate for true lists
Date: Tue, 05 Jun 2018 16:05:04 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Paul Eggert <address@hidden> writes:

> On 06/04/2018 05:12 AM, Basil L. Contovounesios wrote:
>> +(defun list-true-p (object)
>> +  "Return t if OBJECT is a true list.
>> +A true list is neither circular nor dotted (i.e., its last `cdr'
>> +is nil)."
>> +  (null (nthcdr (safe-length object) object)))
>
> This traverses the list twice. Wouldn't it be better to traverse it just once?

Of course.

> Also, why not return the length of the list when it is proper? That would not
> cost anything to compute, and would yield more information than just returning
> t.

I prefer your suggestion to mine.  Would "(elisp) List Elements" be a
more appropriate place to document this function then?

> Like others, I prefer "proper" to "true".

OK, but my question still stands: do we use the term "proper" only to
name this function, but keep existing references to "true" lists in the
manual?  Or do we systematically switch from "true" to "proper", and
possibly add a historical sidenote in the manual documenting this change
in preferred terminology?

> Something like the following, perhaps:
>
> (defun proper-list-length (obj)
>   "Return OBJ's length if OBJ is a proper list, nil otherwise."
>   (and (listp obj) (ignore-errors (length obj))))

LGTM.

Thanks,

-- 
Basil



reply via email to

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