Skip to content

Commit 95d9943

Browse files
updated to work with the new laziness
improvements to syntax highlighting rebuilt dependencies other minor edits
1 parent 64283e4 commit 95d9943

File tree

10 files changed

+44
-34
lines changed

10 files changed

+44
-34
lines changed

README

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ DEPENDENCIES
1515

1616
This version of the sample code has been tested with:
1717

18-
Clojure SVN revision 1279
19-
svn co -r 1279 http://clojure.googlecode.com/svn/trunk/ clojure
18+
Clojure SVN revision 1299
19+
svn co -r 1299 http://clojure.googlecode.com/svn/trunk/ clojure
2020

21-
Clojure-Contrib SVN revision 459:
22-
svn co -r 459 http://clojure-contrib.googlecode.com/svn/trunk/ clojure-contrib
21+
Clojure-Contrib SVN revision 505:
22+
svn co -r 505 http://clojure-contrib.googlecode.com/svn/trunk/ clojure-contrib
2323

24-
Compojure GIT commit 0c8eff9
24+
Compojure GIT commit 0fa49377
2525

2626
-------------------------------------------------------------------------------
2727
You can run the completed Compojure example with

examples/functional.clj

+14-9
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@
5454
:else (fib [0 1] 2))))
5555
; END: fibo-series
5656

57-
; START: lazy-cons-fibo
58-
(defn lazy-cons-fibo []
59-
((fn fib [a b] ; <label id="code.lazy-cons.fib"/>
60-
(lazy-cons a (fib b (+ a b)))) ; <label id="code.lazy-cons.recur"/>
61-
0 1)) ; <label id="code.lazy-cons.basis"/>
62-
; END: lazy-cons-fibo
57+
; START: lazy-seq-fibo
58+
(defn lazy-seq-fibo
59+
([]
60+
(concat [0 1] (lazy-seq-fibo 0 1)))
61+
([a b]
62+
(let [n (+ a b)]
63+
(lazy-seq
64+
(cons n (lazy-seq-fibo b n))))))
65+
; END: lazy-seq-fibo
6366

6467
; START: head-fibo
6568
; holds the head (avoid!)
@@ -80,9 +83,11 @@
8083

8184
; START: by-pairs
8285
(defn by-pairs [coll]
83-
(let [pair (take 2 coll)] ; <label id="code.by-pairs.take"/>
84-
(when (= 2 (count pair)) ; <label id="code.by-pairs.count"/>
85-
(lazy-cons pair (by-pairs (rest coll)))))) ; <label id="code.by-pairs.lazy"/>
86+
(let [take-pair (fn take-pair [c]
87+
(when (next c) (take 2 c)))]
88+
(lazy-seq
89+
(when-let [pair (seq (take-pair coll))]
90+
(cons pair (by-pairs (rest coll)))))))
8691
; END: by-pairs
8792

8893
; START: count-heads-by-pairs

examples/lazy_index_of_any.clj

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
(ns examples.lazy-index-of-any)
22

3-
(defn logging-seq [s]
4-
(if s
5-
(do (println "Iterating over" (first s))
6-
(lazy-cons (first s) (logging-seq (rest s))))))
3+
(defn logging-seq [coll]
4+
(lazy-seq
5+
(when-let [s (seq coll)]
6+
(do (println "Iterating over" (first s))
7+
(cons (first s) (logging-seq (rest s)))))))
78

89
(defn indexed [s] (map vector (iterate inc 0) s (logging-seq s)))
910
(defn index-filter [pred coll]

examples/replace_symbol.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
(defmulti replace-symbol coll-or-scalar) ; <label id="code.replace-symbol.multi"/>
77

88
(defmethod replace-symbol :collection [coll oldsym newsym]
9-
(if (empty? coll)
10-
coll
11-
(lazy-cons (replace-symbol (first coll) oldsym newsym) ; <label id="code.replace-symbol.lazy-cons"/>
12-
(replace-symbol (rest coll) oldsym newsym))))
9+
(lazy-seq
10+
(when-let [s (seq coll)]
11+
(cons (replace-symbol (first coll) oldsym newsym) ; <label id="code.replace-symbol.lazy-cons"/>
12+
(replace-symbol (rest coll) oldsym newsym)))))
1313

1414
(defmethod replace-symbol :scalar [obj oldsym newsym]
1515
(if (= obj oldsym) newsym obj))

examples/test/functional.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
(deftest test-fibo-series
2020
(is (= ten-fibs (fibo-series 10))))
2121

22-
(deftest test-lazy-cons-fibo
23-
(is (= ten-fibs (take 10 (lazy-cons-fibo)))))
22+
(deftest test-lazy-seq-fibo
23+
(is (= ten-fibs (take 10 (lazy-seq-fibo)))))
2424

2525
(deftest test-head-fibo
2626
(is (= ten-fibs (take 10 head-fibo))))

lib/clojure-contrib.jar

9.08 KB
Binary file not shown.

lib/clojure.jar

73.7 KB
Binary file not shown.

lib/compojure.jar

1.84 KB
Binary file not shown.

public/javascripts/clojure.js

+10-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snippets/isBlank.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ public static boolean isBlank(String str) {
55
return true;
66
}
77
for (int i = 0; i < strLen; i++) {
8-
if ((Character.isWhitespace(str.charAt(i)) == false)) {
9-
return false;
10-
}
8+
if ((Character.isWhitespace(str.charAt(i)) == false)) {
9+
return false;
10+
}
1111
}
1212
return true;
1313
}
14-
}
14+
}

0 commit comments

Comments
 (0)