emacs-devel
[Top][All Lists]
Advanced

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

RE: Predicate for true lists


From: Drew Adams
Subject: RE: Predicate for true lists
Date: Fri, 6 Jul 2018 10:16:11 -0700 (PDT)

> > +** New function 'proper-list-length'.
> > +Given a proper list as argument, this function returns its length;
> > +otherwise, it returns nil.  This function can thus be used as a
> > +predicate for proper lists.
> 
> Do we really want this usage of the function as a predicate?  I find
> this slightly unnatural, and also not future-proof enough, because you
> rely on the checks 'length' does internally.  If the internals of
> 'length' change one day, this predicate usage will collapse like a
> house of cards.  Would it make more sense to have a separate
> predicate?

IIRC, the main motivation for adding this function was
to provide a predicate for testing properness.

I see no reason why we should have two functions that
do essentially the same thing: the proposed function
to obtain the length plus a function such as this:

(defun proper-list-p (object)
 "Return non-nil if OBJECT is a proper list."
 (and (proper-list-length object)  t))

We should just have one function, and make clear its
use as a predicate.  If we really want to make that
clear and discoverable then provide `proper-list-p'
as an alias for `proper-list-length'.  That makes
both uses clear without having two functions.

[The name `proper-list-length' can make it sound like
it returns the proper length of a list, not the length
of a proper list.  But I can't think of a better name.
(And `list-proper-length' is what we would really call
a function that did provide the "proper length" of a
list.)]



reply via email to

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