File tree 9 files changed +53
-26
lines changed
9 files changed +53
-26
lines changed Original file line number Diff line number Diff line change @@ -4,16 +4,23 @@ http://www.pragprog.com/titles/shcloj/programming-clojure
4
4
Copyright 2008 Stuart Halloway.
5
5
All rights reserved.
6
6
7
+ -------------------------------------------------------------------------------
8
+ API CHANGES SINCE BETA 5 OF THE BOOK:
9
+
10
+ clojure.contrib.sql:
11
+ * with-query is now with-query-results, query passed as vector
12
+
7
13
-------------------------------------------------------------------------------
8
14
DEPENDENCIES
9
15
10
16
This version of the sample code has been tested with:
11
17
12
- Clojure SVN revision 1205
13
- svn co -r 1205 http://clojure.googlecode.com/svn/trunk/ clojure
18
+ Clojure SVN revision 1215
19
+ svn co -r 1215 http://clojure.googlecode.com/svn/trunk/ clojure
14
20
15
- Clojure-Contrib SVN revision 368:
16
- svn co -r 368 http://clojure-contrib.googlecode.com/svn/trunk/ clojure-contrib
21
+ Clojure-Contrib SVN revision 374:
22
+ svn co -r 374 http://clojure-contrib.googlecode.com/svn/trunk/ clojure-contrib
23
+ Compojure GIT commit dd74dbb6ac4aa2ff4bc516e99666a70d2abf2b0e
17
24
18
25
-------------------------------------------------------------------------------
19
26
You can run the completed Compojure example with
Original file line number Diff line number Diff line change 1
1
# here is a task that is not (yet) easy to write in Clojure...
2
- desc "Build latest Clojure, Clojure-Contrib, and Compojure"
3
- task :book_deps do
2
+ task :build_compojure do
3
+ Dir . chdir ENV [ "COMPOJURE_HOME" ] do
4
+ system "git pull"
5
+ system "ant"
6
+ end
7
+ end
8
+
9
+ task :build_clojure do
4
10
Dir . chdir ENV [ "CLOJURE_HOME" ] do
5
11
system "git svn rebase"
6
12
system "ant jar"
7
13
end
14
+ end
15
+
16
+ task :build_clojure_contrib do
8
17
Dir . chdir ENV [ "CLOJURE_CONTRIB_HOME" ] do
9
18
system "git svn rebase"
10
19
system "ant"
11
20
end
12
- Dir . chdir ENV [ "COMPOJURE_HOME" ] do
13
- system "git pull"
14
- system "ant"
15
- end
21
+ end
22
+
23
+ desc "Get Clojure, Clojure-Contrib, and Compojure from Compojure"
24
+ task :deps_from_compojure => [ :build_compojure ] do
25
+ cp "#{ ENV [ 'COMPOJURE_HOME' ] } /deps/clojure.jar" , "lib/"
26
+ cp "#{ ENV [ 'COMPOJURE_HOME' ] } /deps/clojure-contrib.jar" , "lib/"
27
+ cp "#{ ENV [ 'COMPOJURE_HOME' ] } /compojure.jar" , "lib/"
28
+ end
29
+
30
+ desc "Get all deps from their own projects"
31
+ task :deps => [ :build_clojure , :build_clojure_contrib , :build_compojure ] do
16
32
cp "#{ ENV [ 'CLOJURE_HOME' ] } /clojure.jar" , "lib/"
17
33
cp "#{ ENV [ 'CLOJURE_CONTRIB_HOME' ] } /clojure-contrib.jar" , "lib/"
18
34
cp "#{ ENV [ 'COMPOJURE_HOME' ] } /compojure.jar" , "lib/"
Original file line number Diff line number Diff line change 2
2
3
3
(defn logging-seq [s]
4
4
(if s
5
- (do (println " Iterating over " (first s))
5
+ (do (println " Iterating over" (first s))
6
6
(lazy-cons (first s) (logging-seq (rest s))))))
7
7
8
8
(defn indexed [s] (map vector (iterate inc 0 ) s (logging-seq s)))
Original file line number Diff line number Diff line change 34
34
35
35
(defn sample-snippets []
36
36
(with-connection db
37
- (transaction
38
37
(drop-snippets )
39
38
(create-snippets )
40
- (insert-snippets ))))
39
+ (insert-snippets )))
41
40
42
41
(defn reset-snippets []
43
42
(with-connection db
44
- (transaction
45
43
(drop-snippets )
46
- (create-snippets ))))
44
+ (create-snippets )))
47
45
48
46
(defn ensure-snippets-table-exists []
49
47
(try
50
48
(with-connection db (create-snippets ))
51
- (catch java.sql.BatchUpdateException _)))
49
+ (catch Exception _)))
52
50
53
51
54
52
; START: print-snippets
55
53
(defn print-snippets []
56
- (with-results res " select * from snippets"
54
+ (with-query- results res [ " select * from snippets" ]
57
55
(println res)))
58
56
; END: print-snippets
59
57
60
58
; START: broken-select-snippets
61
59
; Broken!
62
60
(defn select-snippets []
63
- (with-results res " select * from snippets" res))
61
+ (with-query- results res [ " select * from snippets" ] res))
64
62
; END: broken-select-snippets
65
63
(def broken-select-snippets select-snippets )
66
64
71
69
; START: select-snippets
72
70
(defn select-snippets []
73
71
(with-connection db
74
- (with-results res " select * from snippets" (doall res))))
72
+ (with-query- results res [ " select * from snippets" ] (doall res))))
75
73
; END: select-snippets
76
74
77
75
; START: sql-query
78
76
(defn sql-query [q]
79
- (with-results res q (doall res)))
77
+ (with-query- results res [q] (doall res)))
80
78
; END: sql-query
81
79
82
80
(defn select-snippet [id]
Original file line number Diff line number Diff line change 2
2
(:use examples.lazy-index-of-any clojure.contrib.test-is))
3
3
4
4
(deftest test-lazy-index-of-any-with-match
5
- (is (with-out-str (is (zero? (index-of-any " zzabyycdxx" #{\z \a}))))
6
- " Iterating overz \n " )
7
- (is (with-out-str (is (= 3 (index-of-any " zzabyycdxx" #{\b \y}))))
8
- " Iterating overz \n Iterating over z\n Iterating over a\n " ))
5
+ (is (= ( with-out-str (is (zero? (index-of-any " zzabyycdxx" #{\z \a}))))
6
+ " Iterating over z \n " ) )
7
+ (is (= ( with-out-str (is (= 3 (index-of-any " zzabyycdxx" #{\b \y}))))
8
+ " Iterating over z \n Iterating over z\n Iterating over a\n Iterating over b \n " ) ))
9
9
10
10
11
11
Original file line number Diff line number Diff line change 2
2
(:use clojure.contrib.test-is))
3
3
4
4
(deftest test-deftarget-1-refers-to-nonexistent-vars
5
- (let [e (is (thrown? Exception (use :reload 'lancet.deftarget-1)))]
6
- (is (.startsWith (.getMessage e) " java.lang.Exception: Unable to resolve symbol: " ))))
5
+ (let [e (is (thrown? Exception (use :reload 'lancet.deftarget-1)))
6
+ msg-prefix " java.lang.Exception: Unable to resolve symbol: " ]
7
+ (is
8
+ (=
9
+ (.substring (.getMessage e) 0 (count msg-prefix))
10
+ msg-prefix))))
11
+
12
+
7
13
8
14
You can’t perform that action at this time.
0 commit comments