views:

85

answers:

2

I know that I can check whether a list of lists only contains null lists like this

CL-USER> (null (find-if (lambda (item) (not (null item))) my-list))

where my-list is a list of lists.

For example:

CL-USER> (null (find-if (lambda (item) (not (null item))) '(nil (bob) nil)))
NIL
CL-USER> (null (find-if (lambda (item) (not (null item))) '(() () ())))
T

But isn't there a shorter, easier way of doing this in Lisp? If so, how?

+9  A: 

The higher order function every takes a predicate function and a list and returns true iff the predicate returns true for every element in the list.

So you can just do:

(every #'null my-list)
sepp2k
Paul Reiners
+1  A: 
(find-if #'identity list)

(not (find-if-not #'null list))

Consult the Common Lisp HyperSpec for the full list of functions for lists and sequences.

Rainer Joswig