An expression of the form (or foo bar)
does not "glue together" two predicates into one compound predicate; it returns foo
if it is truthy, else bar
. In your code, (fn [x] (divisible x 3))
is of course truthy (the only falsey values are false
and nil
), so the whole thing is equivalent to
((fn [x] (divisible x 3)) 3)
((fn [x] (divisible x 3)) 5)
What you want to do is something like
(some #(apply % 3) [(fn [x] (divisible x 3)) (fn [x] (divisible x 5)])
(some #(apply % 5) [(fn [x] (divisible x 3)) (fn [x] (divisible x 5)])
; ^- here goes the thing being tested
In general,
(defn or-preds [& preds]
(fn [& args]
(some #(apply % args) preds)))
((or-preds (fn [x] (divisible x 3)) (fn [x] (divisible x 5))) 3)
((or-preds (fn [x] (divisible x 3)) (fn [x] (divisible x 5))) 5)
;; or simpler...
((or-preds #(divisible % 3) #(divisible % 5)) 3)