help-gnu-emacs
[Top][All Lists]
Advanced

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

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


From: Robert L.
Subject: Re: What's the canonical way to check "alistp"?
Date: Mon, 5 Mar 2018 19:17:24 +0000 (UTC)
User-agent: XanaNews/1.18.1.6

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


reply via email to

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