Skip to content

Commit 64283e4

Browse files
minor tweaks
1 parent 6b3f812 commit 64283e4

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

examples/memoized_male_female.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
(ns examples.memoized-male-female)
22

3+
; Hofstadter's Male and Female Sequences from GEB
4+
; See http://en.wikipedia.org/wiki/Hofstadter_sequence
35
(declare m f)
46
(defn- m [n]
57
(if (= n 0)

examples/pi.clj

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
([] (.nextDouble *random*))
1414
([n] (* n (.nextDouble *random*))))
1515

16-
; you can try this one to see that thread-local rand
17-
; (above) is not the limiting factor
18-
;(defn waste-time []
19-
; (set! *random* (reduce + (take 100 (iterate inc 1)))))
20-
21-
;(defn tl-rand
22-
; ([] (waste-time) 0.5)
23-
; ([n] (* n (tl-rand))))
24-
2516
(defn random-point []
2617
(let [random-coord (fn [] (dec (tl-rand 2)))]
2718
[(random-coord) (random-coord)]))
@@ -39,7 +30,6 @@
3930

4031
(defmethod run-simulation [java.util.Map Number]
4132
[results n]
42-
(println "Running on " (Thread/currentThread))
4333
(binding [*random* (java.util.Random. (next-seed))]
4434
(reduce (fn [{in-circle :in-circle total :total} point]
4535
(struct sample-results
@@ -56,12 +46,19 @@
5646
(defmethod guess-pi Number [n]
5747
(guess-pi (run-simulation n)))
5848

59-
; START: pguess-pi
6049
(defn parallel-guess-pi [agent-count trials]
6150
(let [trials (quot trials agent-count)
6251
agents (for [_ (range agent-count)] (agent trials))]
6352
(doseq [a agents] (send a run-simulation))
6453
(apply await agents)
6554
(guess-pi (apply merge-with + (map deref agents)))))
66-
; END: pguess-pi
6755

56+
; runs an agent forever
57+
(defn background-pi [iter-count]
58+
(let [agt (agent {:in-circle 0 :total 0})
59+
continue (atom true)
60+
iter (fn sim [a-val]
61+
(when continue (send-off *agent* sim))
62+
(run-simulation a-val iter-count))]
63+
(send-off agt iter)
64+
{:guesser agt :continue atom}))

examples/sequences.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@
8383

8484
(defn demo-xml-seq []
8585
; START:xml-seq
86-
(for [x (xml-seq (parse (java.io.File. "examples/sequences/compositions.xml")))
86+
(for [x (xml-seq
87+
(parse (java.io.File. "examples/sequences/compositions.xml")))
8788
:when (= :composition (:tag x))]
8889
(:composer (:attrs x)))
8990
; END:xml-seq

lancet/step_0/build.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
(def src "src")
55
(def build "classes")
66

7-
(default-target :compile)
8-
97
(deftarget init
108
(tstamp)
119
(mkdir {:dir build}))

0 commit comments

Comments
 (0)