Changes for clojure.core/keep

yasuto on Wed, 25 May 2011
user=> (keep even? (range 1 10))
(false true false true false true false true false)
yasuto on Wed, 25 May 2011
user=> (keep even? (range 1 10))
(false true false true false true false true false)
user> (keep #(if(odd? %) %) (range 10))
(1 3 5 7 9)
user> (keep #(if(even? %) %) (range 10))
(0 2 4 6 8)

(defn keep-mcdr [f coll]
  (lazy-seq
   (when (and (not-empty coll) (first coll))
     (let [x (first coll)
	      xs (rest coll)]
       (cons x  (keep-mcdr f (f x xs)))))))

(defn prime-number [num]
  (cons 1
	(keep-list 
 (fn[x xs] (if (not-empty xs)
	     (keep #(if-not (zero? (rem % x)) %)
		   xs)))
 (range 2 num))))

user> (prime-number 100)
(1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)

dpritchett on Tue, 13 Jul 2010
user=> (keep even? (range 1 10))
(false true false true false true false true false)