From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Robert L." Newsgroups: gmane.emacs.help Subject: Re: What's the canonical way to check "alistp"? Date: Mon, 5 Mar 2018 19:17:24 +0000 (UTC) Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 X-Trace: blaine.gmane.org 1520277503 27001 195.159.176.226 (5 Mar 2018 19:18:23 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Mar 2018 19:18:23 +0000 (UTC) User-Agent: XanaNews/1.18.1.6 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 05 20:18:19 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1esvco-0006QB-8C for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2018 20:18:18 +0100 Original-Received: from localhost ([::1]:51117 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1esveq-0005uT-KD for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Mar 2018 14:20:24 -0500 X-Received: by 10.28.202.2 with SMTP id a2mr1210314wmg.20.1520277447128; Mon, 05 Mar 2018 11:17:27 -0800 (PST) Original-Path: usenet.stanford.edu!139no3482604wmp.0!news-out.google.com!n24ni3292wmi.0!nntp.google.com!proxad.net!feeder1-2.proxad.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 25 Original-NNTP-Posting-Host: D3xOnyMey72xLaL8XEDPVw.user.gioia.aioe.org Original-X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.3 Original-Xref: usenet.stanford.edu gnu.emacs.help:221995 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:116110 Archived-At: On 3/1/2018, Drew Adams wrote: > > What's the best way to check if every element in a list is also a list? > > Also a list or also a cons? Do you want (alistp '(())) > to return true? I'm guessing no. > > (defun alistp (xs) > "Return non-nil iff XS is a list and each element is a cons." > (and (listp xs) > (catch 'alistp > (dolist (x xs) (unless (consp x) (throw 'alistp nil))) > t))) > > (The code should not bother to check each element if it > finds one that is not a cons.) (defun alistp (xs) (and (listp xs) (while (consp (car xs)) (pop xs))) (not xs)) -- [Amazon bans history book after it received 300 5-star reviews.] http://www.tomatobubble.com/worldwarii.html http://archive.org/details/nolies