Checking whether each list in a list is null in Common Lisp

I know that I can check if the list of lists contains only null lists, such as

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

where my-listis a list of lists.

For instance:

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 is there a shorter and easier way to do this in Lisp? If so, how?

+3
source share
2 answers

A higher order everyfunction takes a predicate function and a list and returns true if the predicate returns true for each element in the list.

So you can just do:

(every #'null my-list)
+10
source
(find-if #'identity list)

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

Common Lisp HyperSpec .

+1

Source: https://habr.com/ru/post/1769611/


All Articles