[Top][All Lists]

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

RE: What's the canonical way to check "alistp"?

From: Drew Adams
Subject: RE: What's the canonical way to check "alistp"?
Date: Thu, 1 Mar 2018 09:06:21 -0800 (PST)

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

(The code should not bother to check each element if it
finds one that is not a cons.)

reply via email to

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