From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Stephen J. Turnbull" Newsgroups: gmane.emacs.devel Subject: Re: To be a list or not Date: Sun, 30 Dec 2007 06:11:16 +0900 Message-ID: <87odc96waz.fsf@uwakimon.sk.tsukuba.ac.jp> References: <477568AC.7090304@gmail.com> <18293.28417.122146.27016@kahikatea.snap.net.nz> <47758120.5000507@gmail.com> <18293.35504.41211.784522@kahikatea.snap.net.nz> <4775925A.6020300@gmail.com> <18293.49293.672805.512265@rgrjr.rgrjr.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1198962461 30331 80.91.229.12 (29 Dec 2007 21:07:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 29 Dec 2007 21:07:41 +0000 (UTC) Cc: "Lennart Borgman \(gmail\)" , Emacs Devel To: Bob Rogers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Dec 29 22:07:54 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1J8iuN-0002c2-IB for ged-emacs-devel@m.gmane.org; Sat, 29 Dec 2007 22:07:51 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J8iu2-0000Oi-9u for ged-emacs-devel@m.gmane.org; Sat, 29 Dec 2007 16:07:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J8itc-0008Ma-AH for emacs-devel@gnu.org; Sat, 29 Dec 2007 16:07:04 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J8itb-0008Lx-IY for emacs-devel@gnu.org; Sat, 29 Dec 2007 16:07:03 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J8itb-0008Lk-D5 for emacs-devel@gnu.org; Sat, 29 Dec 2007 16:07:03 -0500 Original-Received: from mtps02.sk.tsukuba.ac.jp ([130.158.97.224]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J8itb-0001mH-3J for emacs-devel@gnu.org; Sat, 29 Dec 2007 16:07:03 -0500 Original-Received: from uwakimon.sk.tsukuba.ac.jp (uwakimon.sk.tsukuba.ac.jp [130.158.99.156]) by mtps02.sk.tsukuba.ac.jp (Postfix) with ESMTP id BE8DD8001; Sun, 30 Dec 2007 06:06:58 +0900 (JST) Original-Received: by uwakimon.sk.tsukuba.ac.jp (Postfix, from userid 1000) id A13531A2E12; Sun, 30 Dec 2007 06:11:17 +0900 (JST) In-Reply-To: <18293.49293.672805.512265@rgrjr.rgrjr.com> X-Mailer: VM 7.17 under 21.5 (beta28) "fuki" (+CVS-20070621) XEmacs Lucid X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:85638 Archived-At: 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) Documentation: Return t if OBJECT is an acyclic, nil-terminated (ie, not dotted), list.