Changes for clojure.core/keep

yasuto on Wed, 25 May 2011
;; Sieve of Eratosthenes by using 'keep'.

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

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

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)
yasuto on Wed, 25 May 2011
(defn keep-mcdr [f coll]
  (lazy-seq
     (when-let [x (first coll)]
       (cons x  (keep-mcdr f (f x (rest coll)))))))

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

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)
yasuto on Wed, 25 May 2011
(defn keep-mcdr [f coll]
  (lazy-seq
     (when-let [x (first coll)]
       (cons x  (keep-mcdr f (f x (rest coll)))))))

(defn prime-number [num]
  (cons 1
	(keep-mcdr
	 (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)
yasuto on Wed, 25 May 2011
(defn keep-mcdr [f coll]
  (lazy-seq
     (when-let [x (first coll)]
       (cons x  (keep-mcdr f (f x (rest coll)))))))

(defn prime-number [num]
  (cons 1
	(keep-mcdr 
 (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)
yasuto on Wed, 25 May 2011
(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-mcdr 
 (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)
yasuto on Wed, 25 May 2011
(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)