[Top][All Lists]

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

Predicate for true lists

From: Basil L. Contovounesios
Subject: Predicate for true lists
Date: Mon, 16 Apr 2018 20:34:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Attachment: 0001-Add-predicate-list-true-p.patch
Description: Add predicate 'list-true-p'

Attachment: bench-list-true-p.el
Description: Benchmark for 'list-true-p'

A while ago, I added a little convenience function to my init file[1]
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.



reply via email to

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