Skip to content

Commit 039b5f0

Browse files
fixes for breaking changes:
* rebuilt dependencies to get consistent version of includes? * changed snippet to use with-query-results instead of query-results * fixed various tests that no longer worked with changed to test-is/is ./bin/snippet-solution.sh is still borked
1 parent 5d0e512 commit 039b5f0

9 files changed

+53
-26
lines changed

README

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ http://www.pragprog.com/titles/shcloj/programming-clojure
44
Copyright 2008 Stuart Halloway.
55
All rights reserved.
66

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+
713
-------------------------------------------------------------------------------
814
DEPENDENCIES
915

1016
This version of the sample code has been tested with:
1117

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
1420

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
1724

1825
-------------------------------------------------------------------------------
1926
You can run the completed Compojure example with

Rakefile

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
# 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
410
Dir.chdir ENV["CLOJURE_HOME"] do
511
system "git svn rebase"
612
system "ant jar"
713
end
14+
end
15+
16+
task :build_clojure_contrib do
817
Dir.chdir ENV["CLOJURE_CONTRIB_HOME"] do
918
system "git svn rebase"
1019
system "ant"
1120
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
1632
cp "#{ENV['CLOJURE_HOME']}/clojure.jar", "lib/"
1733
cp "#{ENV['CLOJURE_CONTRIB_HOME']}/clojure-contrib.jar", "lib/"
1834
cp "#{ENV['COMPOJURE_HOME']}/compojure.jar", "lib/"

examples/lazy_index_of_any.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
(defn logging-seq [s]
44
(if s
5-
(do (println "Iterating over " (first s))
5+
(do (println "Iterating over" (first s))
66
(lazy-cons (first s) (logging-seq (rest s))))))
77

88
(defn indexed [s] (map vector (iterate inc 0) s (logging-seq s)))

examples/snippet.clj

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,31 @@
3434

3535
(defn sample-snippets []
3636
(with-connection db
37-
(transaction
3837
(drop-snippets)
3938
(create-snippets)
40-
(insert-snippets))))
39+
(insert-snippets)))
4140

4241
(defn reset-snippets []
4342
(with-connection db
44-
(transaction
4543
(drop-snippets)
46-
(create-snippets))))
44+
(create-snippets)))
4745

4846
(defn ensure-snippets-table-exists []
4947
(try
5048
(with-connection db (create-snippets))
51-
(catch java.sql.BatchUpdateException _)))
49+
(catch Exception _)))
5250

5351

5452
; START: print-snippets
5553
(defn print-snippets []
56-
(with-results res "select * from snippets"
54+
(with-query-results res ["select * from snippets"]
5755
(println res)))
5856
; END: print-snippets
5957

6058
; START: broken-select-snippets
6159
; Broken!
6260
(defn select-snippets []
63-
(with-results res "select * from snippets" res))
61+
(with-query-results res ["select * from snippets"] res))
6462
; END: broken-select-snippets
6563
(def broken-select-snippets select-snippets)
6664

@@ -71,12 +69,12 @@
7169
; START: select-snippets
7270
(defn select-snippets []
7371
(with-connection db
74-
(with-results res "select * from snippets" (doall res))))
72+
(with-query-results res ["select * from snippets"] (doall res))))
7573
; END: select-snippets
7674

7775
; START: sql-query
7876
(defn sql-query [q]
79-
(with-results res q (doall res)))
77+
(with-query-results res [q] (doall res)))
8078
; END: sql-query
8179

8280
(defn select-snippet [id]

examples/test/lazy_index_of_any.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
(:use examples.lazy-index-of-any clojure.contrib.test-is))
33

44
(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\nIterating over z\nIterating 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\nIterating over z\nIterating over a\nIterating over b\n")))
99

1010

1111

lancet/test/deftarget_1.clj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
(:use clojure.contrib.test-is))
33

44
(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+
713

814

lib/clojure-contrib.jar

2.51 KB
Binary file not shown.

lib/clojure.jar

-2.28 KB
Binary file not shown.

lib/compojure.jar

75.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)