How does one reduce a list of boolean values in Common Lisp?

后端 未结 3 588
迷失自我
迷失自我 2020-12-16 16:15

Given a list of values, I want to reduce the list to T if all the elements are not NIL, NIL if not. This gives me an error:

(apply #\'and (get-some-list))
         


        
3条回答
  •  清歌不尽
    2020-12-16 16:43

    #'and is invalid because and is a macro, not a function.

    You can get around having to define a named function, by using a lambda:

    (reduce (lambda (x y) (and x y)) (get-some-list) :initial-value t)
    

    There's no shortcut like #' though.

    Alternatively you can also use every with the identify function as the predicate.

提交回复
热议问题