Cod*_*lus 2 common-lisp logical-operators higher-order-functions
我经常truth-list喜欢以下内容'(nil nil nil t nil t nil nil nil),我想打个电话(reduce #'or truth-list)
但是,这不起作用,我发现这or是一个宏.有没有一种快速简便的方法可以让它像功能一样工作?我一直在做的是传递:(lambda (p q) (or p q))作为我的功能,但由于我遇到过这么多次,我打赌有更好的方法.
感谢您的帮助!
并不是的.你真的需要这个功能.只需定义一个BINARY-OR函数.如果您经常使用它,那么只需将其添加到您的代码中即可.
备择方案:
(some #'identity '(nil nil nil t nil t nil nil nil))
Run Code Online (Sandbox Code Playgroud)
要么
(loop for i in '(nil nil nil t nil t nil nil nil) thereis i)
Run Code Online (Sandbox Code Playgroud)
额外奖励:以上两种形式都将停在第一个真实值.该reduce变种不会.