Boolean combinators
In the Clojure Tip above, I described a kind of Boolean combinator that lets us build complex rules out of simpler rules. Your task is to build those combinators. Please define:
(defn rule-and
([])
([rule])
([rule1 rule2])
([rule1 rule2 & rules]))
(defn rule-or
([])
([rule])
([rule1 rule2])
([rule1 rule2 & rules]))
(defn rule-not [rule])
Note that rule-and
and rule-or
are monoids and so they
follow the monoid
pattern.
For a bonus, write the functions rule-if
(that implements
the logical if arrow operator) and rule-iff
(that
implements the logical if and only if double-arrow
operator). Not that rule-if
is different from the
programming if
since it returns true
if the condition is
false
.
Please submit your solutions as comments on this gist.
You can use a macro to generate the similar rule-and and rule-or definitions.