all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Kaushal Modi <kaushal.modi@gmail.com>,
	Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: RE: What's the canonical way to check "alistp"?
Date: Thu, 1 Mar 2018 09:06:21 -0800 (PST)	[thread overview]
Message-ID: <5392b397-4974-42cd-9328-161ba7f72f2f@default> (raw)
In-Reply-To: <CAFyQvY1cVaUK03zje1Pxor3H4_hS7-amHg=uxKxX3=Q8GWFuBA@mail.gmail.com>

> 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.)



  parent reply	other threads:[~2018-03-01 17:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01 15:21 What's the canonical way to check "alistp"? Kaushal Modi
2018-03-01 15:29 ` Kaushal Modi
2018-03-01 15:33   ` Dmitry Gutov
2018-03-01 16:36     ` Kaushal Modi
2018-03-01 17:06 ` Drew Adams [this message]
     [not found] ` <mailman.9955.1519924176.27995.help-gnu-emacs@gnu.org>
2018-03-05 19:17   ` Robert L.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5392b397-4974-42cd-9328-161ba7f72f2f@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=kaushal.modi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.