Basil L. Contovounesios
2018-04-16 19:34:00 UTC
to determine whether a given object is a true list (as opposed to a
circular or dotted one):
(null (nthcdr (safe-length object) object))
Since then, I have noticed variations of this predicate/condition strewn
around the Emacs sources, albeit usually implemented less efficiently.
Would such a predicate be a welcome addition to, say, subr.el or
subr-x.el? I attach a first draft of a patch targeting subr.el for your
Also attached is a toy benchmark comparing the new function list-true-p
with the existing format-proper-list-p and ert--proper-list-p when
given, in turn, a true, dotted, and circular list as argument.
It prints the following, after a couple of runs:
true (0.16966186900000002 0 0.0)
dotted (0.168859839 0 0.0)
circular (0.244791363 0 0.0)
true (0.622797443 0 0.0)
dotted (0.621622385 0 0.0)
circular (0.9150398590000001 0 0.0)
true (0.042970005000000006 0 0.0)
dotted (0.04294060500000001 0 0.0)
circular (0.057346661 0 0.0)
P.S. What is the preferred way of formatting car/cdr in docstrings?
The manuals seem to use small caps CAR/CDR and subr.el seems to
alternate between no quotes and `car'/`cdr'. I have gone with the
latter for the docstring of list-true-p, at least for now.