From 3ec1962bfbd760916d95fda4943e17a9385ba523 Mon Sep 17 00:00:00 2001 From: suarela Date: Wed, 16 Aug 2017 13:28:53 +0300 Subject: [PATCH] predicates done --- src/predicates.clj | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/predicates.clj b/src/predicates.clj index 158b1ea..a9781cf 100644 --- a/src/predicates.clj +++ b/src/predicates.clj @@ -1,41 +1,45 @@ (ns predicates) (defn sum-f [f g x] - :-) + (+ (f x) (g x))) (defn less-than [n] - :-) + (fn [k] (< k n))) (defn equal-to [n] - :-) + (fn [k] (== k n))) (defn set->predicate [a-set] - :-) + (fn [x] (contains? a-set x))) (defn pred-and [pred1 pred2] - :-) + (fn [x] (and (pred1 x) + (pred2 x)))) (defn pred-or [pred1 pred2] - :-) + (fn [x] (or (pred1 x) + (pred2 x)))) (defn whitespace? [character] (Character/isWhitespace character)) (defn blank? [string] - :-) + (every? whitespace? string)) (defn has-award? [book award] - :-) + ((set->predicate (:awards book)) award)) (defn HAS-ALL-THE-AWARDS? [book awards] - :-) + (every? (set->predicate (:awards book)) awards)) (defn my-some [pred a-seq] - :-) + (first (filter boolean (map pred a-seq)))) (defn my-every? [pred a-seq] - :-) + (== (count (filter pred a-seq)) + (count a-seq))) (defn prime? [n] - :-) + (let [pred (fn [x] (== 0 (mod n x )))] + (not (some pred (range 2 n))))) ;^^