[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Predicate for true lists
From: |
Paul Eggert |
Subject: |
Re: Predicate for true lists |
Date: |
Mon, 4 Jun 2018 18:23:39 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 |
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? 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. Like others, I prefer "proper" to "true".
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))))
Re: Predicate for true lists,
Paul Eggert <=
Re: Predicate for true lists, Basil L. Contovounesios, 2018/06/05
- Re: Predicate for true lists, Paul Eggert, 2018/06/06
- Re: Predicate for true lists, Van L, 2018/06/06
- Re: Predicate for true lists, Stefan Monnier, 2018/06/06
- Re: Predicate for true lists, Stefan Monnier, 2018/06/06
- Re: Predicate for true lists, Van L, 2018/06/07