[Top][All Lists]

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

Re: To be a list or not

From: Stephen J. Turnbull
Subject: Re: To be a list or not
Date: Sun, 30 Dec 2007 06:11:16 +0900

Bob Rogers writes:

 > This is called an "improper list"; you could check for it thus:
 >      (defun proper-list-p (x)
 >        (and (listp x)
 >             (null (cdr (last x)))))

But please call it `true-list-p', which is the name of the similar
XEmacs built-in.  The XEmacs built-in uses a tortoise-hare algorithm
to ensure that cyclic lists are caught.  I don't know who may have
touched it so I won't post code here.

As several people have pointed out, it's still O(n).  In most cases it
make a lot more sense to use a condition-case around your list-
processing code and handle the error thrown appropriately only for the
last cons.

`true-list-p' is a built-in function
  -- loaded from "/playpen/src/XEmacs/git-integration/src/data.c"
(true-list-p OBJECT)

Return t if OBJECT is an acyclic, nil-terminated (ie, not dotted), list.

reply via email to

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