CodeKingPlusPlus
CodeKingPlusPlus

Reputation: 16081

common-lisp higher-order logical or function

I often have a truth-list like the following '(nil nil nil t nil t nil nil nil) and I would like to call (reduce #'or truth-list)

However, this does not work and I found that or is a macro. Is there a quick and easy way I can get this to work like a function? What I have been doing is passing: (lambda (p q) (or p q)) as my function, but since I have come across this so many times, I bet there is a better way.

Thanks for all the help!

Upvotes: 2

Views: 127

Answers (1)

Rainer Joswig
Rainer Joswig

Reputation: 139381

Not really. You actually need the function. Just define a BINARY-OR function. If you use it often, then just add it to your code.

Alternatives:

(some #'identity '(nil nil nil t nil t nil nil nil))

or

(loop for i in '(nil nil nil t nil t nil nil nil) thereis i)

Bonus: both above forms will stop at the first true value. The reduce variant won't.

Upvotes: 5

Related Questions