Browse files

Replace replicate (deprecated) by repeat

  • Loading branch information...
1 parent 7679776 commit c48d268dc69eb4d7dcabff2d65188d9cd18230e3 @jafingerhut jafingerhut committed with khinsen Feb 5, 2014
Showing with 6 additions and 6 deletions.
  1. +4 −4 src/examples/clojure/examples/monads.clj
  2. +2 −2 src/test/clojure/clojure/algo/test_monads.clj
View
8 src/examples/clojure/examples/monads.clj
@@ -82,7 +82,7 @@
; This definition suggests a generalization:
(with-monad sequence-m
(defn ntuples [n xs]
- (m-seq (replicate n xs))))
+ (m-seq (repeat n xs))))
(ntuples 2 (range 5))
(ntuples 3 (range 5))
@@ -222,14 +222,14 @@
; of + to be lifted to the state monad:
(def gaussian2
(domonad state-m
- [sum12 (reduce (m-lift 2 +) (replicate 12 rng))]
+ [sum12 (reduce (m-lift 2 +) (repeat 12 rng))]
(- sum12 6.)))
; Such a reduction is often quite useful, so there's m-reduce predefined
; to simplify it:
(def gaussian2
(domonad state-m
- [sum12 (m-reduce + (replicate 12 rng))]
+ [sum12 (m-reduce + (repeat 12 rng))]
(- sum12 6.)))
; The statistics should be strictly the same as above, as long as
@@ -242,7 +242,7 @@
(with-monad state-m
(def gaussian3
((m-lift 1 #(- % 6.))
- (m-reduce + (replicate 12 rng)))))
+ (m-reduce + (repeat 12 rng)))))
; Again, the statistics are the same:
(mean (take 1000 (value-seq gaussian3 1)))
View
4 src/test/clojure/clojure/algo/test_monads.clj
@@ -90,9 +90,9 @@
'((1 1) (2 0))
((m-lift 2 #(list %1 %2)) (range 3) (range 2))
'((0 0) (0 1) (1 0) (1 1) (2 0) (2 1))
- (m-seq (replicate 3 (range 2)))
+ (m-seq (repeat 3 (range 2)))
'((0 0 0) (0 0 1) (0 1 0) (0 1 1) (1 0 0) (1 0 1) (1 1 0) (1 1 1))
- ((m-chain (replicate 3 range)) 5)
+ ((m-chain (repeat 3 range)) 5)
'(0 0 0 1 0 0 1 0 1 2)
(m-plus (range 3) (range 2))
'(0 1 2 0 1))))

0 comments on commit c48d268

Please sign in to comment.