I cannot use logical functions on a range of booleans in Clojure (1.2). Neither of the following works due to logical functions being macros:
(reduce and [... sequence of bools ...]) (apply or [... sequence of bools ...])
The error message says that I "can't take value of a macro: #'clojure.core/and
". How to apply these logical functions (macros) without writing boilerplate code?
Reduces a collection using a (potentially parallel) reduce-combine strategy. The collection is par... Added by jcburley. clojure.core/partition-by. Applies f to each value in coll, splitting it each time f returns a new value.
Reducers provide an alternative approach to using sequences to manipulate standard Clojure collections. Sequence functions are typically applied lazily, in order, create intermediate results, and in a single thread.
Don't -- use every?
and some
instead.
Michal's answer is already spot on, but the following alternative approach can be useful in similar situations whenever you want to use a macro as a function:
(reduce #(and %1 %2) [... sequence of bools ...])
Basically you just wrap the macro in an anonymous function.
There are a couple of good reasons to consider this approach:
some
or every?
does not existIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With