Browse files

updating for latest edition

  • Loading branch information...
1 parent 5a94c59 commit 05f654590c30f61a97545103d69283350a009be2 @abedra abedra committed Sep 27, 2011
Showing with 8,680 additions and 2,199 deletions.
  1. +3 −0 .gitignore
  2. +15 −15 README.markdown
  3. +0 −35 Rakefile
  4. +0 −1 bin/reader-tasklist.bat
  5. +0 −1 bin/reader-tasklist.sh
  6. +0 −1 bin/repl.bat
  7. +0 −1 bin/repl.sh
  8. +0 −1 bin/runtests.bat
  9. +0 −1 bin/runtests.sh
  10. +0 −1 bin/snippet-solution.bat
  11. +0 −1 bin/snippet-solution.sh
  12. +0 −1 bin/snippet.bat
  13. +0 −1 bin/snippet.sh
  14. +0 −1 bin/tasklist.bat
  15. +0 −1 bin/tasklist.sh
  16. BIN classes/examples/tasklist$_init__419.class
  17. BIN classes/examples/tasklist$_main__425.class
  18. BIN classes/examples/tasklist$_startElement__422.class
  19. BIN classes/examples/tasklist$task_list__416.class
  20. BIN classes/examples/tasklist.class
  21. BIN classes/examples/tasklist__init.class
  22. +0 −1 classes/reader/.gitignore
  23. +5 −0 data/.svn/all-wcprops
  24. +34 −0 data/.svn/entries
  25. +11 −0 data/sequences/.svn/all-wcprops
  26. +62 −0 data/sequences/.svn/entries
  27. 0 examples/sequences/compositions.xml → data/sequences/.svn/text-base/compositions.xml.svn-base
  28. +12 −0 data/sequences/compositions.xml
  29. +47 −0 data/snippets/.svn/all-wcprops
  30. +266 −0 data/snippets/.svn/entries
  31. +25 −0 data/snippets/.svn/text-base/Person.java.svn-base
  32. 0 snippets/StringUtils.java → data/snippets/.svn/text-base/StringUtils.java.svn-base
  33. 0 snippets/bootstrap-mysql.clj → data/snippets/.svn/text-base/bootstrap-mysql.clj.svn-base
  34. 0 snippets/example-build.xml → data/snippets/.svn/text-base/example-build.xml.svn-base
  35. +14 −0 data/snippets/.svn/text-base/isBlank.java.svn-base
  36. 0 snippets/macros.clj → data/snippets/.svn/text-base/macros.clj.svn-base
  37. 0 snippets/xml_callback.clj → data/snippets/.svn/text-base/xml_callback.clj.svn-base
  38. +25 −0 data/snippets/Person.java
  39. +15 −0 data/snippets/StringUtils.java
  40. +7 −0 data/snippets/bootstrap-mysql.clj
  41. +63 −0 data/snippets/example-build.xml
  42. +14 −0 data/snippets/isBlank.java
  43. +39 −0 data/snippets/macros.clj
  44. +15 −0 data/snippets/xml_callback.clj
  45. +0 −22 examples/index_of_any.clj
  46. +0 −55 examples/server/complete.clj
  47. +0 −18 examples/server/step_1.clj
  48. +0 −51 examples/server/step_2.clj
  49. +0 −64 examples/server/step_3.clj
  50. +0 −101 examples/snippet.clj
  51. +0 −31 examples/test/chat.clj
  52. +0 −11 examples/test/macros/bench_1.clj
  53. +0 −12 examples/test/multimethods/default.clj
  54. +0 −25 examples/test/snippet.clj
  55. +0 −11 lancet/deftarget_1.clj
  56. +0 −10 lancet/snippets.clj
  57. +0 −14 lancet/step_0/build.clj
  58. +0 −17 lancet/step_0/build.xml
  59. +0 −25 lancet/step_1_complete.clj
  60. +0 −36 lancet/step_1_repl.clj
  61. +0 −41 lancet/step_2_complete.clj
  62. +0 −48 lancet/step_2_repl.clj
  63. +0 −23 lancet/step_3.clj
  64. +0 −28 lancet/step_3_complete.clj
  65. +0 −19 lancet/step_3_repl.clj
  66. +0 −39 lancet/step_4_complete.clj
  67. +0 −63 lancet/step_4_repl.clj
  68. +0 −57 lancet/step_5_complete.clj
  69. +0 −69 lancet/step_5_repl.clj
  70. +0 −14 lancet/test/deftarget_1.clj
  71. +0 −15 lancet/test/step_1_complete.clj
  72. +0 −29 lancet/test/step_1_repl.clj
  73. +0 −41 lancet/test/step_2_complete.clj
  74. +0 −41 lancet/test/step_2_repl.clj
  75. +0 −38 lancet/test/step_3_complete.clj
  76. +0 −20 lancet/test/step_3_repl.clj
  77. +0 −28 lancet/test/step_4_complete.clj
  78. +0 −33 lancet/test/step_4_repl.clj
  79. +0 −14 lancet/test/step_5_complete.clj
  80. +0 −20 lancet/test/step_5_repl.clj
  81. +0 −94 lib/CPL.txt
  82. +0 −8 lib/LICENSES
  83. BIN lib/ant-launcher.jar
  84. BIN lib/ant.jar
  85. +0 −201 lib/apache_license
  86. BIN lib/clojure-contrib.jar
  87. BIN lib/clojure.jar
  88. BIN lib/commons-codec-1.3.jar
  89. BIN lib/commons-fileupload-1.2.1.jar
  90. BIN lib/compojure.jar
  91. +0 −261 lib/epl-v10.html
  92. BIN lib/hsqldb.jar
  93. +0 −66 lib/hsqldb_license
  94. BIN lib/jetty-6.1.14.jar
  95. BIN lib/jetty-util-6.1.14.jar
  96. BIN lib/jline-0.9.94.jar
  97. +0 −33 lib/jline_license
  98. BIN lib/servlet-api-2.5-6.1.14.jar
  99. +14 −0 project.clj
  100. +0 −20 snippets/Person.java
  101. +0 −14 snippets/isBlank.java
  102. +5 −0 src/.svn/all-wcprops
  103. +34 −0 src/.svn/entries
  104. +221 −0 src/examples/.svn/all-wcprops
  105. +1,261 −0 src/examples/.svn/entries
  106. +130 −0 src/examples/.svn/text-base/atom_snake.clj.svn-base
  107. +32 −0 src/examples/.svn/text-base/chat.clj.svn-base
  108. +45 −0 src/examples/.svn/text-base/concurrency.clj.svn-base
  109. +72 −0 src/examples/.svn/text-base/cryptovault.clj.svn-base
  110. +56 −0 src/examples/.svn/text-base/cryptovault_complete.clj.svn-base
  111. 0 examples/error_kit.clj → src/examples/.svn/text-base/error_kit.clj.svn-base
  112. +9 −0 src/examples/.svn/text-base/expectorate.clj.svn-base
  113. +128 −0 src/examples/.svn/text-base/exploring.clj.svn-base
  114. +166 −0 src/examples/.svn/text-base/functional.clj.svn-base
  115. +18 −0 src/examples/.svn/text-base/generator.clj.svn-base
  116. +15 −0 src/examples/.svn/text-base/gulp.clj.svn-base
  117. +18 −0 src/examples/.svn/text-base/index_of_any.clj.svn-base
  118. 0 examples/interop.clj → src/examples/.svn/text-base/interop.clj.svn-base
  119. +42 −0 src/examples/.svn/text-base/introduction.clj.svn-base
  120. +72 −0 src/examples/.svn/text-base/io.clj.svn-base
  121. 0 examples/lazy_index_of_any.clj → src/examples/.svn/text-base/lazy_index_of_any.clj.svn-base
  122. +38 −0 src/examples/.svn/text-base/life_without_multi.clj.svn-base
  123. 0 examples/macros.clj → src/examples/.svn/text-base/macros.clj.svn-base
  124. 0 examples/male_female.clj → src/examples/.svn/text-base/male_female.clj.svn-base
  125. +22 −0 src/examples/.svn/text-base/male_female_seq.clj.svn-base
  126. 0 examples/memoized_male_female.clj → src/examples/.svn/text-base/memoized_male_female.clj.svn-base
  127. +34 −0 src/examples/.svn/text-base/midi.clj.svn-base
  128. +58 −0 src/examples/.svn/text-base/multimethods.clj.svn-base
  129. 0 examples/pi.clj → src/examples/.svn/text-base/pi.clj.svn-base
  130. 0 examples/preface.clj → src/examples/.svn/text-base/preface.clj.svn-base
  131. +20 −0 src/examples/.svn/text-base/primes.clj.svn-base
  132. +155 −0 src/examples/.svn/text-base/protocols.clj.svn-base
  133. 0 examples/replace_symbol.clj → src/examples/.svn/text-base/replace_symbol.clj.svn-base
  134. +94 −0 src/examples/.svn/text-base/sequences.clj.svn-base
  135. +170 −0 src/examples/.svn/text-base/snake.clj.svn-base
  136. +103 −0 src/examples/.svn/text-base/snippet.clj.svn-base
  137. +37 −0 src/examples/.svn/text-base/tasklist.clj.svn-base
  138. +31 −0 src/examples/.svn/text-base/test.clj.svn-base
  139. 0 examples/trampoline.clj → src/examples/.svn/text-base/trampoline.clj.svn-base
  140. +64 −0 src/examples/.svn/text-base/utils.clj.svn-base
  141. 0 examples/wallingford.clj → src/examples/.svn/text-base/wallingford.clj.svn-base
  142. +2 −3 { → src}/examples/atom_snake.clj
  143. +2 −2 { → src}/examples/chat.clj
  144. +2 −3 { → src}/examples/concurrency.clj
  145. +72 −0 src/examples/cryptovault.clj
  146. +56 −0 src/examples/cryptovault_complete.clj
  147. +53 −0 src/examples/error_kit.clj
  148. +9 −0 src/examples/expectorate.clj
  149. +10 −10 { → src}/examples/exploring.clj
  150. +15 −16 { → src}/examples/functional.clj
  151. +18 −0 src/examples/generator.clj
  152. +15 −0 src/examples/gulp.clj
  153. +18 −0 src/examples/index_of_any.clj
  154. +116 −0 src/examples/interop.clj
  155. +2 −1 { → src}/examples/introduction.clj
  156. +72 −0 src/examples/io.clj
  157. +14 −0 src/examples/lazy_index_of_any.clj
  158. +2 −2 { → src}/examples/life_without_multi.clj
  159. +58 −0 src/examples/macros.clj
  160. +41 −0 src/examples/macros/.svn/all-wcprops
  161. +232 −0 src/examples/macros/.svn/entries
  162. 0 examples/macros/bench_1.clj → src/examples/macros/.svn/text-base/bench_1.clj.svn-base
  163. 0 examples/macros/chain_1.clj → src/examples/macros/.svn/text-base/chain_1.clj.svn-base
  164. 0 examples/macros/chain_2.clj → src/examples/macros/.svn/text-base/chain_2.clj.svn-base
  165. 0 examples/macros/chain_3.clj → src/examples/macros/.svn/text-base/chain_3.clj.svn-base
  166. 0 examples/macros/chain_4.clj → src/examples/macros/.svn/text-base/chain_4.clj.svn-base
  167. 0 examples/macros/chain_5.clj → src/examples/macros/.svn/text-base/chain_5.clj.svn-base
  168. +11 −0 src/examples/macros/bench_1.clj
  169. +6 −0 src/examples/macros/chain_1.clj
  170. +6 −0 src/examples/macros/chain_2.clj
  171. +5 −0 src/examples/macros/chain_3.clj
  172. +7 −0 src/examples/macros/chain_4.clj
  173. +6 −0 src/examples/macros/chain_5.clj
  174. +16 −0 src/examples/male_female.clj
  175. +2 −2 { → src}/examples/male_female_seq.clj
  176. +20 −0 src/examples/memoized_male_female.clj
  177. +34 −0 src/examples/midi.clj
  178. +3 −3 { → src}/examples/multimethods.clj
  179. +35 −0 src/examples/multimethods/.svn/all-wcprops
  180. +198 −0 src/examples/multimethods/.svn/entries
  181. 0 examples/multimethods/account.clj → src/examples/multimethods/.svn/text-base/account.clj.svn-base
  182. 0 examples/multimethods/default.clj → src/examples/multimethods/.svn/text-base/default.clj.svn-base
  183. 0 ...ods/service_charge_1.clj → src/examples/multimethods/.svn/text-base/service_charge_1.clj.svn-base
  184. 0 ...ods/service_charge_2.clj → src/examples/multimethods/.svn/text-base/service_charge_2.clj.svn-base
  185. 0 ...ods/service_charge_3.clj → src/examples/multimethods/.svn/text-base/service_charge_3.clj.svn-base
  186. +22 −0 src/examples/multimethods/account.clj
  187. +9 −0 src/examples/multimethods/default.clj
  188. +15 −0 src/examples/multimethods/service_charge_1.clj
  189. +13 −0 src/examples/multimethods/service_charge_2.clj
  190. +20 −0 src/examples/multimethods/service_charge_3.clj
  191. +64 −0 src/examples/pi.clj
  192. +5 −0 src/examples/preface.clj
  193. +20 −0 src/examples/primes.clj
  194. +155 −0 src/examples/protocols.clj
  195. +27 −0 src/examples/replace_symbol.clj
  196. +2 −2 { → src}/examples/sequences.clj
  197. +29 −0 src/examples/server/.svn/all-wcprops
  198. +164 −0 src/examples/server/.svn/entries
  199. +54 −0 src/examples/server/.svn/text-base/complete.clj.svn-base
  200. +17 −0 src/examples/server/.svn/text-base/step_1.clj.svn-base
  201. +45 −0 src/examples/server/.svn/text-base/step_2.clj.svn-base
  202. +57 −0 src/examples/server/.svn/text-base/step_3.clj.svn-base
  203. +54 −0 src/examples/server/complete.clj
  204. +17 −0 src/examples/server/step_1.clj
  205. +45 −0 src/examples/server/step_2.clj
  206. +57 −0 src/examples/server/step_3.clj
  207. +2 −3 { → src}/examples/snake.clj
  208. +103 −0 src/examples/snippet.clj
  209. +2 −2 { → src}/examples/tasklist.clj
  210. +1 −1 { → src}/examples/test.clj
  211. +31 −0 src/examples/trampoline.clj
  212. +4 −5 { → src}/examples/utils.clj
  213. +26 −0 src/examples/wallingford.clj
  214. +23 −0 src/reader/.svn/all-wcprops
  215. +130 −0 src/reader/.svn/entries
  216. +10 −0 src/reader/.svn/text-base/snake.clj.svn-base
  217. 0 reader/snippet_server.clj → src/reader/.svn/text-base/snippet_server.clj.svn-base
  218. +10 −0 src/reader/.svn/text-base/tasklist.clj.svn-base
  219. +2 −3 { → src}/reader/snake.clj
  220. +4 −0 src/reader/snippet_server.clj
  221. +1 −1 { → src}/reader/tasklist.clj
  222. +5 −0 test/.svn/all-wcprops
  223. +31 −0 test/.svn/entries
  224. +5 −0 test/examples/.svn/all-wcprops
  225. +31 −0 test/examples/.svn/entries
  226. +143 −0 test/examples/test/.svn/all-wcprops
  227. +816 −0 test/examples/test/.svn/entries
  228. +26 −0 test/examples/test/.svn/text-base/chat.clj.svn-base
  229. +26 −0 test/examples/test/.svn/text-base/concurrency.clj.svn-base
  230. +79 −0 test/examples/test/.svn/text-base/exploring.clj.svn-base
  231. +14 −0 test/examples/test/.svn/text-base/fail.clj.svn-base
  232. +35 −0 test/examples/test/.svn/text-base/functional.clj.svn-base
  233. +21 −0 test/examples/test/.svn/text-base/index_of_any.clj.svn-base
  234. +45 −0 test/examples/test/.svn/text-base/interop.clj.svn-base
  235. +34 −0 test/examples/test/.svn/text-base/introduction.clj.svn-base
  236. +11 −0 test/examples/test/.svn/text-base/lazy_index_of_any.clj.svn-base
  237. +23 −0 test/examples/test/.svn/text-base/life_without_multi.clj.svn-base
  238. +38 −0 test/examples/test/.svn/text-base/macros.clj.svn-base
  239. +11 −0 test/examples/test/.svn/text-base/male_female.clj.svn-base
  240. +11 −0 test/examples/test/.svn/text-base/male_female_seq.clj.svn-base
  241. +11 −0 test/examples/test/.svn/text-base/memoized_male_female.clj.svn-base
  242. +25 −0 test/examples/test/.svn/text-base/multimethods.clj.svn-base
  243. +11 −0 test/examples/test/.svn/text-base/preface.clj.svn-base
  244. +14 −0 test/examples/test/.svn/text-base/replace_symbol.clj.svn-base
  245. +47 −0 test/examples/test/.svn/text-base/sequences.clj.svn-base
  246. +46 −0 test/examples/test/.svn/text-base/snake.clj.svn-base
  247. +20 −0 test/examples/test/.svn/text-base/snippet.clj.svn-base
  248. +16 −0 test/examples/test/.svn/text-base/tasklist.clj.svn-base
  249. +16 −0 test/examples/test/.svn/text-base/trampoline.clj.svn-base
  250. +12 −0 test/examples/test/.svn/text-base/wallingford.clj.svn-base
  251. +26 −0 test/examples/test/chat.clj
  252. +8 −11 { → test}/examples/test/concurrency.clj
  253. +23 −37 { → test}/examples/test/exploring.clj
  254. +6 −6 { → test}/examples/test/fail.clj
  255. +5 −6 { → test}/examples/test/functional.clj
  256. +3 −3 { → test}/examples/test/index_of_any.clj
  257. +2 −2 { → test}/examples/test/interop.clj
  258. +2 −2 { → test}/examples/test/introduction.clj
  259. +1 −1 { → test}/examples/test/lazy_index_of_any.clj
  260. +5 −8 { → test}/examples/test/life_without_multi.clj
  261. +9 −13 { → test}/examples/test/macros.clj
  262. +41 −0 test/examples/test/macros/.svn/all-wcprops
  263. +232 −0 test/examples/test/macros/.svn/entries
  264. +11 −0 test/examples/test/macros/.svn/text-base/bench_1.clj.svn-base
  265. +7 −0 test/examples/test/macros/.svn/text-base/chain_1.clj.svn-base
  266. +7 −0 test/examples/test/macros/.svn/text-base/chain_2.clj.svn-base
  267. +7 −0 test/examples/test/macros/.svn/text-base/chain_3.clj.svn-base
  268. +7 −0 test/examples/test/macros/.svn/text-base/chain_4.clj.svn-base
  269. +7 −0 test/examples/test/macros/.svn/text-base/chain_5.clj.svn-base
  270. +11 −0 test/examples/test/macros/bench_1.clj
  271. +3 −4 { → test}/examples/test/macros/chain_1.clj
  272. +3 −4 { → test}/examples/test/macros/chain_2.clj
  273. +3 −4 { → test}/examples/test/macros/chain_3.clj
  274. +3 −4 { → test}/examples/test/macros/chain_4.clj
  275. +3 −4 { → test}/examples/test/macros/chain_5.clj
  276. +2 −2 { → test}/examples/test/male_female.clj
  277. +2 −2 { → test}/examples/test/male_female_seq.clj
  278. +2 −2 { → test}/examples/test/memoized_male_female.clj
  279. +7 −11 { → test}/examples/test/multimethods.clj
  280. +35 −0 test/examples/test/multimethods/.svn/all-wcprops
  281. +198 −0 test/examples/test/multimethods/.svn/entries
  282. +18 −0 test/examples/test/multimethods/.svn/text-base/account.clj.svn-base
  283. +10 −0 test/examples/test/multimethods/.svn/text-base/default.clj.svn-base
  284. +13 −0 test/examples/test/multimethods/.svn/text-base/service_charge_1.clj.svn-base
  285. +13 −0 test/examples/test/multimethods/.svn/text-base/service_charge_2.clj.svn-base
  286. +13 −0 test/examples/test/multimethods/.svn/text-base/service_charge_3.clj.svn-base
  287. +6 −9 { → test}/examples/test/multimethods/account.clj
  288. +10 −0 test/examples/test/multimethods/default.clj
  289. +4 −7 { → test}/examples/test/multimethods/service_charge_1.clj
  290. +4 −7 { → test}/examples/test/multimethods/service_charge_2.clj
  291. +4 −7 { → test}/examples/test/multimethods/service_charge_3.clj
  292. +2 −2 { → test}/examples/test/preface.clj
  293. +3 −5 { → test}/examples/test/replace_symbol.clj
  294. +12 −18 { → test}/examples/test/sequences.clj
  295. +2 −2 { → test}/examples/test/snake.clj
  296. +20 −0 test/examples/test/snippet.clj
  297. +3 −3 { → test}/examples/test/tasklist.clj
  298. +2 −4 { → test}/examples/test/trampoline.clj
  299. +3 −5 { → test}/examples/test/wallingford.clj
  300. +0 −2 user.clj
View
3 .gitignore
@@ -7,3 +7,6 @@
/snippet-db.properties
/snippet-db.script
/tmp.clj
+lib/*
+.lein-failures
+classes/*
View
30 README.markdown
@@ -1,17 +1,24 @@
# Sample Code for Programming Clojure
-http://www.pragprog.com/titles/shcloj/programming-clojure
+http://www.pragprog.com/titles/shcloj2/programming-clojure
+Copyright 2011 Stuart Halloway and Aaron Bedra. All rights reserved.
-Copyright 2008-2010 Stuart Halloway. All rights reserved.
+# Important Notice
-# Getting Started
+If you are reading the first edition of the book sure you grab the
+first-edition branch of this project instead, from
+
+https://github.com/stuarthalloway/programming-clojure/tree/first-edition
-This (master) branch of the repository has all the files as referenced
-from the book Programming Clojure. All the necessary libraries are
-already installed. You should be able to start a REPL with:
+The first-edition branch has all the files exactly where the book says they
+will be.
+
+# Getting Started
-* `bin/repl.sh` (Unix, Mac)
-* `bin\repl.bat` (Windows)
+* Make sure you have Java installed.
+* Make sure you have [leiningen](http://github.com/technomancy/leiningen) installed.
+* Run `lein deps` to install all the dependent libraries.
+* Run `script/repl` to launch a repl.
# Want more Clojure Practice?
@@ -23,10 +30,3 @@ for exploring the Clojure language. It includes:
* an interactive repl for working with the lab exercises
* solutions with passing tests
* up-to-date versions of Clojure, contrib, incanter, compojure and other libraries to explore
-
-# Want Training?
-
-Rich Hickey, the creator of Clojure, and Stuart Halloway, the author
-of Programming Clojure, provide Clojure training through the
-[Pragmatic Studio](http://pragmaticstudio.com/clojure).
-
View
35 Rakefile
@@ -1,35 +0,0 @@
-# here is a task that is not (yet) easy to write in Clojure...
-task :build_compojure do
- Dir.chdir ENV["COMPOJURE_HOME"] do
- system "git pull"
- system "ant clean jar" # Clojure compiler changes may necessitate a clean
- end
-end
-
-task :build_clojure do
- Dir.chdir ENV["CLOJURE_HOME"] do
- system "git pull"
- system "ant jar"
- end
-end
-
-task :build_clojure_contrib do
- Dir.chdir ENV["CLOJURE_CONTRIB_HOME"] do
- system "git pull"
- system "ant -Dclojure.jar=../clojure/clojure.jar clean jar" # Clojure compiler changes may necessitate a clean
- end
-end
-
-desc "Get Clojure, Clojure-Contrib, and Compojure from Compojure"
-task :deps_from_compojure => [:build_compojure] do
- cp "#{ENV['COMPOJURE_HOME']}/deps/clojure.jar", "lib/"
- cp "#{ENV['COMPOJURE_HOME']}/deps/clojure-contrib.jar", "lib/"
- cp "#{ENV['COMPOJURE_HOME']}/compojure.jar", "lib/"
-end
-
-desc "Get all deps from their own projects"
-task :deps => [:build_clojure, :build_clojure_contrib, :build_compojure] do
- cp "#{ENV['CLOJURE_HOME']}/clojure.jar", "lib/"
- cp "#{ENV['CLOJURE_CONTRIB_HOME']}/clojure-contrib.jar", "lib/"
- cp "#{ENV['COMPOJURE_HOME']}/compojure.jar", "lib/"
-end
View
1 bin/reader-tasklist.bat
@@ -1 +0,0 @@
-java -cp classes;lib/clojure.jar;lib/clojure-contrib.jar reader.tasklist %1 %2 %3 %4 %5 %6 %7 %8 %9
View
1 bin/reader-tasklist.sh
@@ -1 +0,0 @@
-java -cp classes:lib/clojure.jar:lib/clojure-contrib.jar reader.tasklist $@
View
1 bin/repl.bat
@@ -1 +0,0 @@
-java -cp .;lib/commons-io-1.4.jar;lib/commons-fileupload-1.2.1.jar;lib/commons-codec-1.3.jar;lib/jline-0.9.94.jar;lib/clojure.jar;lib/clojure-contrib.jar;lib/ant.jar;lib/ant-launcher.jar;lib/compojure.jar;lib/hsqldb.jar;lib/jetty-6.1.14.jar;lib/jetty-util-6.1.14.jar;lib/servlet-api-2.5-6.1.14.jar;classes jline.ConsoleRunner clojure.lang.Repl
View
1 bin/repl.sh
@@ -1 +0,0 @@
-java -cp .:lib/commons-io-1.4.jar:lib/commons-fileupload-1.2.1.jar:lib/commons-codec-1.3.jar:lib/jline-0.9.94.jar:lib/clojure.jar:lib/clojure-contrib.jar:lib/ant.jar:lib/ant-launcher.jar:lib/compojure.jar:lib/hsqldb.jar:lib/jetty-6.1.14.jar:lib/jetty-util-6.1.14.jar:lib/servlet-api-2.5-6.1.14.jar:classes jline.ConsoleRunner clojure.lang.Repl
View
1 bin/runtests.bat
@@ -1 +0,0 @@
-java -Xmx1G -cp lib/clojure.jar;lib/clojure-contrib.jar;lib/hsqldb.jar;lib/ant.jar;lib/ant-launcher.jar;.;classes clojure.lang.Script examples/test.clj
View
1 bin/runtests.sh
@@ -1 +0,0 @@
-java -Xmx1G -cp lib/clojure.jar:lib/clojure-contrib.jar:lib/hsqldb.jar:lib/ant.jar:lib/ant-launcher.jar:.:classes clojure.lang.Script examples/test.clj
View
1 bin/snippet-solution.bat
@@ -1 +0,0 @@
-java -cp .;lib/commons-io-1.4.jar;lib/commons-fileupload-1.2.1.jar;lib/commons-codec-1.3.jar;lib/jline-0.9.94.jar;lib/clojure.jar;lib/clojure-contrib.jar;lib/compojure.jar;lib/hsqldb.jar;lib/jetty-6.1.14.jar;lib/jetty-util-6.1.14.jar;lib/servlet-api-2.5-6.1.14.jar jline.ConsoleRunner clojure.lang.Repl examples/server/complete.clj
View
1 bin/snippet-solution.sh
@@ -1 +0,0 @@
-java -cp .:lib/commons-io-1.4.jar:lib/commons-fileupload-1.2.1.jar:lib/commons-codec-1.3.jar:lib/jline-0.9.94.jar:lib/clojure.jar:lib/clojure-contrib.jar:lib/compojure.jar:lib/hsqldb.jar:lib/jetty-6.1.14.jar:lib/jetty-util-6.1.14.jar:lib/servlet-api-2.5-6.1.14.jar jline.ConsoleRunner clojure.lang.Repl examples/server/complete.clj
View
1 bin/snippet.bat
@@ -1 +0,0 @@
-java -cp .;lib/commons-io-1.4.jar;lib/commons-fileupload-1.2.1.jar;lib/commons-codec-1.3.jar;lib/jline-0.9.94.jar;lib/clojure.jar;lib/clojure-contrib.jar;lib/compojure.jar;lib/hsqldb.jar;lib/jetty-6.1.14.jar;lib/jetty-util-6.1.14.jar;lib/servlet-api-2.5-6.1.14.jar jline.ConsoleRunner clojure.lang.Repl reader/snippet_server.clj
View
1 bin/snippet.sh
@@ -1 +0,0 @@
-java -cp .:lib/commons-io-1.4.jar:lib/commons-fileupload-1.2.1.jar:lib/commons-codec-1.3.jar:lib/jline-0.9.94.jar:lib/clojure.jar:lib/clojure-contrib.jar:lib/compojure.jar:lib/hsqldb.jar:lib/jetty-6.1.14.jar:lib/jetty-util-6.1.14.jar:lib/servlet-api-2.5-6.1.14.jar jline.ConsoleRunner clojure.lang.Repl reader/snippet_server.clj
View
1 bin/tasklist.bat
@@ -1 +0,0 @@
-java -cp classes;lib/clojure.jar;lib/clojure-contrib.jar examples.tasklist %1 %2 %3 %4 %5 %6 %7 %8 %9
View
1 bin/tasklist.sh
@@ -1 +0,0 @@
-java -cp classes:lib/clojure.jar:lib/clojure-contrib.jar examples.tasklist $@
View
BIN classes/examples/tasklist$_init__419.class
Binary file not shown.
View
BIN classes/examples/tasklist$_main__425.class
Binary file not shown.
View
BIN classes/examples/tasklist$_startElement__422.class
Binary file not shown.
View
BIN classes/examples/tasklist$task_list__416.class
Binary file not shown.
View
BIN classes/examples/tasklist.class
Binary file not shown.
View
BIN classes/examples/tasklist__init.class
Binary file not shown.
View
1 classes/reader/.gitignore
@@ -1 +0,0 @@
-*.class
View
5 data/.svn/all-wcprops
@@ -0,0 +1,5 @@
+K 25
+svn:wc:ra_dav:version-url
+V 55
+/Bookshelf/!svn/ver/93881/titles/shcloj2/Book/code/data
+END
View
34 data/.svn/entries
@@ -0,0 +1,34 @@
+10
+
+dir
+104723
+https://svn.pragprog.com/Bookshelf/titles/shcloj2/Book/code/data
+https://svn.pragprog.com/Bookshelf
+
+
+
+2011-04-08T17:38:06.087802Z
+93881
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+82263e25-b5eb-0310-b4ec-9460fbaf34b7
+
+snippets
+dir
+
+sequences
+dir
+
View
11 data/sequences/.svn/all-wcprops
@@ -0,0 +1,11 @@
+K 25
+svn:wc:ra_dav:version-url
+V 65
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/sequences
+END
+compositions.xml
+K 25
+svn:wc:ra_dav:version-url
+V 82
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/sequences/compositions.xml
+END
View
62 data/sequences/.svn/entries
@@ -0,0 +1,62 @@
+10
+
+dir
+104723
+https://svn.pragprog.com/Bookshelf/titles/shcloj2/Book/code/data/sequences
+https://svn.pragprog.com/Bookshelf
+
+
+
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+82263e25-b5eb-0310-b4ec-9460fbaf34b7
+
+compositions.xml
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+88ddfb54c0c4c3d23f5e92987f44572e
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+296
+
View
0 examples/sequences/compositions.xml → .../.svn/text-base/compositions.xml.svn-base
File renamed without changes.
View
12 data/sequences/compositions.xml
@@ -0,0 +1,12 @@
+<compositions>
+ <composition composer="J. S. Bach">
+ <name>The Art of the Fugue</name>
+ </composition>
+ <composition composer="J. S. Bach">
+ <name>Musical Offering</name>
+ </composition>
+ <composition composer="W. A. Mozart">
+ <name>Requiem</name>
+ </composition>
+</compositions>
+
View
47 data/snippets/.svn/all-wcprops
@@ -0,0 +1,47 @@
+K 25
+svn:wc:ra_dav:version-url
+V 64
+/Bookshelf/!svn/ver/93881/titles/shcloj2/Book/code/data/snippets
+END
+isBlank.java
+K 25
+svn:wc:ra_dav:version-url
+V 77
+/Bookshelf/!svn/ver/93881/titles/shcloj2/Book/code/data/snippets/isBlank.java
+END
+xml_callback.clj
+K 25
+svn:wc:ra_dav:version-url
+V 81
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/snippets/xml_callback.clj
+END
+Person.java
+K 25
+svn:wc:ra_dav:version-url
+V 76
+/Bookshelf/!svn/ver/93737/titles/shcloj2/Book/code/data/snippets/Person.java
+END
+StringUtils.java
+K 25
+svn:wc:ra_dav:version-url
+V 81
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/snippets/StringUtils.java
+END
+bootstrap-mysql.clj
+K 25
+svn:wc:ra_dav:version-url
+V 84
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/snippets/bootstrap-mysql.clj
+END
+example-build.xml
+K 25
+svn:wc:ra_dav:version-url
+V 82
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/snippets/example-build.xml
+END
+macros.clj
+K 25
+svn:wc:ra_dav:version-url
+V 75
+/Bookshelf/!svn/ver/93730/titles/shcloj2/Book/code/data/snippets/macros.clj
+END
View
266 data/snippets/.svn/entries
@@ -0,0 +1,266 @@
+10
+
+dir
+104723
+https://svn.pragprog.com/Bookshelf/titles/shcloj2/Book/code/data/snippets
+https://svn.pragprog.com/Bookshelf
+
+
+
+2011-04-08T17:38:06.087802Z
+93881
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+82263e25-b5eb-0310-b4ec-9460fbaf34b7
+
+isBlank.java
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+73e32bf4786ce5c95a3297d6da5d6b45
+2011-04-08T17:38:06.087802Z
+93881
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+382
+
+xml_callback.clj
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+ea356dc23d806e684ab47110b03f9b6e
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+413
+
+Person.java
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+a297e6df3e083144842eac83c2cbfa16
+2011-04-06T01:06:24.046606Z
+93737
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+529
+
+StringUtils.java
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+2b78610171c940d0a148672d858d1414
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+398
+
+bootstrap-mysql.clj
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+3f60d4cc4f82fb389668c6857d691e12
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+290
+
+example-build.xml
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+3247ca1a541d2be5e5c78ea9bf07b46f
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1992
+
+macros.clj
+file
+
+
+
+
+2011-05-10T19:19:53.490816Z
+f38590f1f0f33007174c3c61f4e9617d
+2011-04-05T22:43:27.355235Z
+93730
+aaron.bedra
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+1338
+
View
25 data/snippets/.svn/text-base/Person.java.svn-base
@@ -0,0 +1,25 @@
+public class Person {
+ private String firstName;
+ private String lastName;
+
+ public Person(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
View
0 snippets/StringUtils.java → .../.svn/text-base/StringUtils.java.svn-base
File renamed without changes.
View
0 snippets/bootstrap-mysql.clj → ...vn/text-base/bootstrap-mysql.clj.svn-base
File renamed without changes.
View
0 snippets/example-build.xml → ....svn/text-base/example-build.xml.svn-base
File renamed without changes.
View
14 data/snippets/.svn/text-base/isBlank.java.svn-base
@@ -0,0 +1,14 @@
+public class StringUtils {
+ public static boolean isBlank(String str) {
+ int strLen;
+ if (str == null || (strLen = str.length()) == 0) {
+ return true;
+ }
+ for (int i = 0; i < strLen; i++) {
+ if ((Character.isWhitespace(str.charAt(i)) == false)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
View
0 snippets/macros.clj → ...ippets/.svn/text-base/macros.clj.svn-base
File renamed without changes.
View
0 snippets/xml_callback.clj → .../.svn/text-base/xml_callback.clj.svn-base
File renamed without changes.
View
25 data/snippets/Person.java
@@ -0,0 +1,25 @@
+public class Person {
+ private String firstName;
+ private String lastName;
+
+ public Person(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+}
View
15 data/snippets/StringUtils.java
@@ -0,0 +1,15 @@
+// From Apache Commons Lang, http://commons.apache.org/lang/
+public static int indexOfAny(String str, char[] searchChars) {
+ if (isEmpty(str) || ArrayUtils.isEmpty(searchChars)) {
+ return -1;
+ }
+ for (int i = 0; i < str.length(); i++) {
+ char ch = str.charAt(i);
+ for (int j = 0; j < searchChars.length; j++) {
+ if (searchChars[j] == ch) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
View
7 data/snippets/bootstrap-mysql.clj
@@ -0,0 +1,7 @@
+(defn bootstrap-mysql
+ ([]
+ (bootstrap-mysql "file:///Users/stuart/devtools/java/mysql-connector-java-5.0.6/mysql-connector-java-5.0.6-bin.jar"))
+ ([jar]
+ (add-classpath jar)
+ (java.sql.DriverManager/registerDriver (.newInstance (Class/forName "com.mysql.jdbc.Driver")))))
+
View
63 data/snippets/example-build.xml
@@ -0,0 +1,63 @@
+<!-- example build script, taken from Clojure itself -->
+<project name="clojure" default="all">
+
+ <description>
+ Build with "ant jar" and then start the REPL with:
+ "java -cp clojure.jar clojure.main"
+ </description>
+
+ <property name="src" location="src"/>
+ <property name="jsrc" location="${src}/jvm"/>
+ <property name="cljsrc" location="${src}/clj"/>
+ <property name="build" location="classes"/>
+ <property name="clojure_jar" location="clojure.jar"/>
+ <property name="slim_jar" location="clojure-slim.jar"/>
+
+ <target name="init" depends="clean">
+ <tstamp/>
+ <mkdir dir="${build}"/>
+ </target>
+
+ <!-- START: target -->
+ <target name="compile-java" depends="init"
+ description="Compile Java sources.">
+ <!-- END: target -->
+ <javac srcdir="${jsrc}" destdir="${build}" includeJavaRuntime="yes"
+ debug="true" target="1.5"/>
+ </target>
+
+ <target name="compile-clojure" depends="compile-java"
+ description="Compile Clojure sources.">
+ <java classname="clojure.lang.Compile"
+ classpath="${build}:${cljsrc}">
+ <sysproperty key="clojure.compile.path" value="${build}"/>
+ <arg value="clojure.core"/>
+ <arg value="clojure.main"/>
+ <arg value="clojure.set"/>
+ <arg value="clojure.xml"/>
+ <arg value="clojure.zip"/>
+ <arg value="clojure.inspector"/>
+ </java>
+ </target>
+
+ <target name="clojure" depends="compile-clojure"
+ description="Create clojure jar file.">
+ <jar jarfile="${clojure_jar}" basedir="${build}">
+ <fileset dir="${cljsrc}" includes="**/*.clj"/>
+ <manifest>
+ <attribute name="Main-Class" value="clojure.main"/>
+ <attribute name="Class-Path" value="."/>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="jar" depends="clojure"/>
+
+ <target name="all" depends="clojure,clojure-slim"/>
+
+ <target name="clean"
+ description="Remove autogenerated files and directories.">
+ <delete dir="${build}"/>
+ </target>
+
+</project>
View
14 data/snippets/isBlank.java
@@ -0,0 +1,14 @@
+public class StringUtils {
+ public static boolean isBlank(String str) {
+ int strLen;
+ if (str == null || (strLen = str.length()) == 0) {
+ return true;
+ }
+ for (int i = 0; i < strLen; i++) {
+ if ((Character.isWhitespace(str.charAt(i)) == false)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
View
39 data/snippets/macros.clj
@@ -0,0 +1,39 @@
+;; NOT for execution. These are excerpts from Clojure
+;; and are subject to the Clojure License, repeated below:
+
+; Copyright (c) Rich Hickey. All rights reserved.
+; The use and distribution terms for this software are covered by the
+; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
+; which can be found in the file CPL.TXT at the root of this distribution.
+; By using this software in any fashion, you are agreeing to be bound by
+; the terms of this license.
+; You must not remove this notice, or any other, from this software.
+
+; START: and
+(defmacro and
+ ([] true)
+ ([x] x)
+ ([x & rest]
+ `(let [and# ~x] ; <label id="macros.and.let"/>
+ (if and# (and ~@rest) and#)))) ; <label id="macros.and.if"/>
+; END: and
+
+; START: with-out-str
+(defmacro with-out-str
+ [& body] ; <label id="macros.with.varargs"/>
+ `(let [s# (new java.io.StringWriter)] ; <label id="macros.with.let"/>
+ (binding [*out* s#] ; <label id="macros.with.bindings"/>
+ ~@body ; <label id="macros.with.splice"/>
+ (str s#)))) ; <label id="macros.with.result"/>
+; END: with-out-str
+
+; START: defstruct
+(defmacro defstruct
+ [name & keys]
+ `(def ~name (create-struct ~@keys)))
+; END: defstruct
+
+; START: declare
+(defmacro declare
+ [& names] `(do ~@(map #(list 'def %) names)))
+; END: declare
View
15 data/snippets/xml_callback.clj
@@ -0,0 +1,15 @@
+; redacted from Clojure's xml.clj to focus on dynamic variable usage
+(startElement
+ [uri local-name q-name #^Attributes atts]
+ ; details omitted
+ (set! *stack* (conj *stack* *current*))
+ (set! *current* e)
+ (set! *state* :element))
+nil)
+(endElement
+ [uri local-name q-name]
+ ; details omitted
+ (set! *current* (push-content (peek *stack*) *current*))
+ (set! *stack* (pop *stack*))
+ (set! *state* :between)
+nil)
View
22 examples/index_of_any.clj
@@ -1,22 +0,0 @@
-(ns examples.index-of-any
- (:use clojure.contrib.seq-utils))
-
-; START: index-of-any
-(defn index-filter [pred coll]
- (when pred (for [[idx elt] (indexed coll) :when (pred elt)] idx)))
-
-(defn
- #^{:test (fn []
- (assert (nil? (index-of-any #{\a} nil)))
- (assert (nil? (index-of-any #{\a} "")))
- (assert (nil? (index-of-any nil "foo")))
- (assert (nil? (index-of-any #{} "foo")))
- (assert (zero? (index-of-any #{\z \a} "zzabyycdxx")))
- (assert (= 3 (index-of-any #{\b \y} "zzabyycdxx")))
- (assert (nil? (index-of-any #{\z} "aba"))))}
- index-of-any
- [pred coll]
- (first (index-filter pred coll)))
-; END: index-of-any
-
-
View
55 examples/server/complete.clj
@@ -1,55 +0,0 @@
-(ns examples.server.complete
- (:use compojure examples.snippet))
-
-(defn layout [title & body]
- (html
- [:head
- [:title title]
- (include-js "/public/javascripts/code-highlighter.js" "/public/javascripts/clojure.js")
- (include-css "/public/stylesheets/code-highlighter.css")]
- [:body
- [:h2 title]
- body]))
-
-(defn new-snippet []
- (layout "Create a Snippet"
- (form-to [:post "/"]
- (text-area {:rows 20 :cols 73} "body")
- [:br]
- (submit-button "Save"))))
-
-(defn create-snippet [body]
- (if-let [id (insert-snippet body)]
- (redirect-to (str "/" id))
- (redirect-to "/")))
-
-(defn show-snippet [id]
- (layout (str "Snippet " id)
- (let [snippet (select-snippet id)]
- (html
- [:div [:pre [:code.clojure (:body snippet)]]]
- [:div.date (:created_at snippet)]))))
-
-(defroutes snippet-app
- "Create and view snippets."
- (GET "/ping" "Pong")
-
- (GET "/"
- (new-snippet))
-
- (GET "/:id"
- (show-snippet (params :id)))
-
- (POST "/"
- (create-snippet (:body params)))
-
- (GET "/public/*"
- (or (serve-file (params :*)) :next))
-
- (ANY "*"
- (page-not-found)))
-
-(ensure-snippets-table-exists)
-(run-server {:port 8080}
- "/*" (servlet snippet-app))
-
View
18 examples/server/step_1.clj
@@ -1,18 +0,0 @@
-(ns examples.server.step-1)
-
-; START: defroutes
-(use 'compojure)
-(defroutes snippet-app
- "Create and view snippets."
- (GET "/ping" "pong")
-
- (ANY "*"
- (page-not-found)))
-; END: defroutes
-
-; START: run-server
-(run-server {:port 8080}
- "/*" (servlet snippet-app))
-; END: run-server
-
-
View
51 examples/server/step_2.clj
@@ -1,51 +0,0 @@
-(ns examples.server.step-2
- (:use compojure examples.snippet))
-
-; START: new-snippet
-(defn new-snippet []
- (html
- (form-to [:post "/"]
- (text-area {:rows 20 :cols 73} "body")
- [:br]
- (submit-button "Save"))))
-; END: new-snippet
-
-; START: create-snippet
-(defn create-snippet [body]
- (if-let [id (insert-snippet body)]
- (redirect-to (str "/" id))
- (redirect-to "/")))
-; END: create-snippet
-
-; START: show-snippet
-(defn show-snippet [id]
- (let [snippet (select-snippet id)]
- (html
- [:div [:pre [:code (:body snippet)]]]
- [:div (:created_at snippet)])))
-; END: show-snippet
-
-(defroutes snippet-app
- "Create and view snippets."
- (GET "/ping" "Pong")
-
- ; START: handlers
- (GET "/"
- (new-snippet))
-
- (GET "/:id"
- (show-snippet (params :id)))
-
- (POST "/"
- (create-snippet (:body params)))
- ; END: handlers
-
- (ANY "*"
- (page-not-found)))
-
-(ensure-snippets-table-exists)
-(run-server {:port 8080}
- "/*" (servlet snippet-app))
-
-
-
View
64 examples/server/step_3.clj
@@ -1,64 +0,0 @@
-(ns examples.server.step-3
- (:use compojure examples.snippet))
-
-; START: layout
-(defn layout [title & body]
- (html
- [:head
- [:title title]
- (include-js "/public/javascripts/code-highlighter.js"
- "/public/javascripts/clojure.js")
- (include-css "/public/stylesheets/code-highlighter.css")]
- [:body
- [:h2 title]
- body]))
-; END: layout
-
-; START: new-snippet
-(defn new-snippet []
- (layout "Create a Snippet"
- (form-to [:post "/"]
- (text-area {:rows 20 :cols 73} "body")
- [:br]
- (submit-button "Save"))))
-; END: new-snippet
-
-(defn create-snippet [body]
- (if-let [id (insert-snippet body)]
- (redirect-to (str "/" id))
- (redirect-to "/")))
-
-; START: show-snippet
-(defn show-snippet [id]
- (layout (str "Snippet " id)
- (let [snippet (select-snippet id)]
- (html
- [:div [:pre [:code.clojure (:body snippet)]]]
- [:div (:created_at snippet)]))))
-; END: show-snippet
-
-(defroutes snippet-app
- "Create and view snippets."
- (GET "/ping" "Pong")
-
- (GET "/"
- (new-snippet))
-
- (GET "/:id"
- (show-snippet (params :id)))
-
- (POST "/"
- (create-snippet (:body params)))
-
- ; START: public
- (GET "/public/*"
- (or (serve-file (params :*)) :next))
- ; END: public
-
- (ANY "*"
- (page-not-found)))
-
-(ensure-snippets-table-exists)
-(run-server {:port 8080}
- "/*" (servlet snippet-app))
-
View
101 examples/snippet.clj
@@ -1,101 +0,0 @@
-(ns examples.snippet)
-
-; START: create-snippets
-(use 'clojure.contrib.sql)
-(defn create-snippets []
- (create-table :snippets
- [:id :int "IDENTITY" "PRIMARY KEY"]
- [:body :varchar "NOT NULL"]
- [:created_at :datetime]))
-; END: create-snippets
-
-; START: db
-; replace "snippet-db" with a full path!
-(def db {:classname "org.hsqldb.jdbcDriver"
- :subprotocol "hsqldb"
- :subname "file:snippet-db"})
-; END: db
-
-(defn drop-snippets []
- (try
- (drop-table :snippets)
- (catch Exception e)))
-
-; START: insert-snippets
-(defn now [] (java.sql.Timestamp. (.getTime (java.util.Date.))))
-(defn insert-snippets []
- (let [timestamp (now)]
- (seq
- (insert-values :snippets
- [:body :created_at]
- ["(println :boo)" timestamp]
- ["(defn foo [] 1)" timestamp]))))
-; END: insert-snippets
-
-(defn sample-snippets []
- (with-connection db
- (drop-snippets)
- (create-snippets)
- (insert-snippets)))
-
-(defn reset-snippets []
- (with-connection db
- (drop-snippets)
- (create-snippets)))
-
-(defn ensure-snippets-table-exists []
- (try
- (with-connection db (create-snippets))
- (catch Exception _)))
-
-
-; START: print-snippets
-(defn print-snippets []
- (with-query-results res ["select * from snippets"]
- (println res)))
-; END: print-snippets
-
-; START: broken-select-snippets
-; Broken!
-(defn select-snippets []
- (with-query-results res ["select * from snippets"] res))
-; END: broken-select-snippets
-(def broken-select-snippets select-snippets)
-
-(defmulti coerce (fn [dest-class src-inst] [dest-class (class src-inst)]))
-(defmethod coerce [Integer String] [_ inst] (Integer/parseInt inst))
-(defmethod coerce :default [dest-cls obj] (cast dest-cls obj))
-
-; START: select-snippets
-(defn select-snippets []
- (with-connection db
- (with-query-results res ["select * from snippets"] (doall res))))
-; END: select-snippets
-
-; START: sql-query
-(defn sql-query [q]
- (with-query-results res q (doall res)))
-; END: sql-query
-
-(defn select-snippet [id]
- (with-connection db
- (first (sql-query ["select * from snippets where id = ?" (coerce Integer id)]))))
-
-; START: last-created-id
-(defn last-created-id
- "Extract the last created id. Must be called in a transaction
- that performed an insert. Expects HSQLDB return structure of
- the form [{:@p0 id}]."
- []
- (first (vals (first (sql-query ["CALL IDENTITY()"])))))
-; END: last-created-id
-
-; START: insert-snippet
-(defn insert-snippet [body]
- (with-connection db
- (transaction
- (insert-values :snippets
- [:body :created_at]
- [body (now)])
- (last-created-id))))
-; END: insert-snippet
View
31 examples/test/chat.clj
@@ -1,31 +0,0 @@
-(ns examples.test.chat
- (:use clojure.contrib.test-is)
- (:require examples.chat))
-
-(alias 'c 'examples.chat)
-
-(deftest naive-add-message
- (dosync (ref-set c/messages ()))
- (c/naive-add-message (struct c/message "jdoe" "hello"))
- (is (= '({:sender "jdoe" :text "hello"}) @c/messages))
-)
-
-(deftest add-message
- (dosync (ref-set c/messages ()))
- (c/add-message (struct c/message "jdoe" "goodbye"))
- (is (= '({:sender "jdoe" :text "goodbye"}) @c/messages))
-)
-
-(deftest add-message-commute
- (dosync (ref-set c/messages ()))
- (c/add-message-commute (struct c/message "jdoe" "goodbye"))
- (is (= '({:sender "jdoe" :text "goodbye"}) @c/messages))
-)
-
-(deftest validate-message-list
- (is (true? (c/validate-message-list ())))
- (is (true? (c/validate-message-list '({:sender "X" :text "Y"}))))
- (is (nil? (c/validate-message-list '({}))))
-)
-
-
View
11 examples/test/macros/bench_1.clj
@@ -1,11 +0,0 @@
-(ns examples.test.macros.bench-1
- (:use clojure.contrib.test-is examples.macros.bench-1))
-
-(deftest test-bench-1
- (are (= _1 _2)
- (macroexpand-1 '(examples.macros.bench-1/bench :foo))
- '(clojure.core/let [examples.macros.bench-1/start (System/nanoTime)
- examples.macros.bench-1/result :foo]
- {:elapsed (clojure.core/- (System/nanoTime) examples.macros.bench-1/start),
- :result examples.macros.bench-1/result})))
-
View
12 examples/test/multimethods/default.clj
@@ -1,12 +0,0 @@
-(ns examples.test.multimethods.default
- (:use clojure.contrib.test-is)
- (:use examples.multimethods.default))
-
-(deftest test-my-print
- (are (= _1 _2)
- (with-out-str (my-print "foo")) "foo"
- (with-out-str (my-print 42)) "Not implemented yet..."
-))
-
-
-
View
25 examples/test/snippet.clj
@@ -1,25 +0,0 @@
-(ns examples.test.snippet
- (:use clojure.contrib.test-is clojure.contrib.sql examples.snippet))
-
-(deftest insert-and-select-some-snippets
- (let [stub-time (now)]
- (binding [now (fn [] stub-time)]
- (sample-snippets)
- (is (= [{:id 0, :body "(println :boo)", :created_at stub-time}
- {:id 1, :body "(defn foo [] 1)", :created_at stub-time}]
- (select-snippets)))
- (insert-snippet "boo!")
- (is (= {:id 2, :body "boo!", :created_at stub-time}
- (select-snippet 2))))))
-
-(deftest drop-and-create-snippets-table
- (with-connection db (drop-snippets))
- (is (= "Table not found in statement [select * from snippets]"
- (.getMessage (is (thrown? java.sql.SQLException (select-snippets))))))
- (ensure-snippets-table-exists)
- (is (= () (select-snippets))))
-
-
-
-
-
View
11 lancet/deftarget_1.clj
@@ -1,11 +0,0 @@
-(ns lancet.deftarget-1)
-; broken for demo purposes, correct version is in lancet/step_4_repl.clj
-
-; START: deftarget
-(defmacro deftarget [sym doc & forms]
- `(let [[has-run-fn reset-fn once-fn] (runonce (fn [] ~@forms))]
- (def ~(with-meta sym {:has-run-fn has-run-fn
- :reset-fn reset-fn
- :doc doc})
- once-fn)))
-; END: deftarget
View
10 lancet/snippets.clj
@@ -1,10 +0,0 @@
-; not executable! don't load this
-
-; START: set-property!
-(use '[clojure.contrib.except :only (throw-if)])
-(defn set-property! [inst prop value]
- (let [pd (property-descriptor inst prop)]
- (throw-if (nil? pd) (str "No such property " prop))
- (.invoke (.getWriteMethod pd) inst (into-array [value])))) ; <label id="sequences.lancet.value"/>
-; END: set-property!
-
View
14 lancet/step_0/build.clj
@@ -1,14 +0,0 @@
-(use 'lancet)
-(use 'lancet.ant)
-
-(def src "src")
-(def build "classes")
-
-(deftarget init
- (tstamp)
- (mkdir {:dir build}))
-
-(deftarget compile
- "Compile Java sources"
- (init)
- (javac {:srcdir src :destdir build}))
View
17 lancet/step_0/build.xml
@@ -1,17 +0,0 @@
-<project name="example" default="compile">
-
- <property name="src" location="src"/>
- <property name="build" location="classes"/>
-
- <target name="init">
- <tstamp/>
- <mkdir dir="${build}"/>
- </target>
-
- <target name="compile" depends="init"
- description="Compile Java sources.">
- <javac srcdir="${src}"
- destdir="${build}"/>
- </target>
-
-</project>
View
25 lancet/step_1_complete.clj
@@ -1,25 +0,0 @@
-(ns lancet.step-1-complete
- (:use clojure.contrib.except))
-
-(def
- #^{:doc "Dummy ant project to keep Ant tasks happy"}
- ant-project
- (let [proj (org.apache.tools.ant.Project.)
- logger (org.apache.tools.ant.NoBannerLogger.)]
- (doto logger
- (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
- (.setOutputPrintStream System/out)
- (.setErrorPrintStream System/err))
- (doto proj
- (.init)
- (.addBuildListener logger))))
-
-(defn instantiate-task [project name]
- (let [task (.createTask project name)]
- (throw-if (nil? task)
- IllegalArgumentException (str "No task named " name))
- (doto task
- (.init)
- (.setProject project))))
-
-
View
36 lancet/step_1_repl.clj
@@ -1,36 +0,0 @@
-(ns lancet.step-1-repl)
-
-; START: ant-project
-(def
- #^{:doc "Dummy ant project to keep Ant tasks happy"} ; <label id="interop.lancet.doc"/>
- ant-project ; <label id="interop.lancet.var"/>
- (let [proj (org.apache.tools.ant.Project.) ; <label id="interop.lancet.let"/>
- logger (org.apache.tools.ant.NoBannerLogger.)]
- (doto logger ; <label id="interop.lancet.logger"/>
- (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
- (.setOutputPrintStream System/out)
- (.setErrorPrintStream System/err))
- (doto proj ; <label id="interop.lancet.proj"/>
- (.init)
- (.addBuildListener logger))))
-; END: ant-project
-
-; START: instantiate-task
-(defn instantiate-task [project name]
- (let [task (.createTask project name)]
- (doto task
- (.init)
- (.setProject project))))
-; END: instantiate-task
-
-; START: safe-instantiate-task
-(use '[clojure.contrib.except :only (throw-if)])
-(defn safe-instantiate-task [project name]
- (let [task (.createTask project name)]
- (throw-if (nil? task)
- IllegalArgumentException (str "No task named " name))
- (doto task
- (.init)
- (.setProject project))))
-; END: safe-instantiate-task
-
View
41 lancet/step_2_complete.clj
@@ -1,41 +0,0 @@
-(ns lancet.step-2-complete
- (:use clojure.contrib.except)
- (:import (java.beans Introspector)))
-
-(def
- #^{:doc "Dummy ant project to keep Ant tasks happy"}
- ant-project
- (let [proj (org.apache.tools.ant.Project.)
- logger (org.apache.tools.ant.NoBannerLogger.)]
- (doto logger
- (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
- (.setOutputPrintStream System/out)
- (.setErrorPrintStream System/err))
- (doto proj
- (.init)
- (.addBuildListener logger))))
-
-(defn property-descriptor [inst prop-name]
- (first
- (filter #(= (name prop-name) (.getName %))
- (.getPropertyDescriptors
- (Introspector/getBeanInfo (class inst))))))
-
-(defn set-property! [inst prop value]
- (let [pd (property-descriptor inst prop)]
- (throw-if (nil? pd) (str "No such property " prop))
- (.invoke (.getWriteMethod pd) inst (into-array [value]))))
-
-(defn set-properties! [inst prop-map]
- (doseq [[k v] prop-map] (set-property! inst k v)))
-
-(defn instantiate-task [project name props]
- (let [task (.createTask project name)]
- (throw-if (nil? task) (str "No task named " name))
- (doto task
- (.init)
- (.setProject project)
- (set-properties! props))
- task))
-
-
View
48 lancet/step_2_repl.clj
@@ -1,48 +0,0 @@
-(ns lancet.step-2-repl)
-
-(def
- #^{:doc "Dummy ant project to keep Ant tasks happy"}
- ant-project
- (let [proj (org.apache.tools.ant.Project.)
- logger (org.apache.tools.ant.NoBannerLogger.)]
- (doto logger
- (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
- (.setOutputPrintStream System/out)
- (.setErrorPrintStream System/err))
- (doto proj
- (.init)
- (.addBuildListener logger))))
-
-; START: property-descriptor
-(import '(java.beans Introspector))
-(defn property-descriptor [inst prop-name]
- (first
- (filter #(= (name prop-name) (.getName %))
- (.getPropertyDescriptors
- (Introspector/getBeanInfo (class inst))))))
-; END: property-descriptor
-
-; START: set-property!
-(use '[clojure.contrib.except :only (throw-if)])
-(defn set-property! [inst prop value]
- (let [pd (property-descriptor inst prop)] ; <label id="sequences.lancet.let"/>
- (throw-if (nil? pd) (str "No such property " prop)) ; <label id="sequences.lancet.throw-if"/>
- (.invoke (.getWriteMethod pd) inst (into-array [value])))) ; <label id="sequences.lancet.into-array"/>
-; END: set-property!
-
-; START: set-properties!
-(defn set-properties! [inst prop-map]
- (doseq [[k v] prop-map] (set-property! inst k v)))
-; END: set-properties!
-
-; START: instantiate-task
-(defn instantiate-task [project name props]
- (let [task (.createTask project name)]
- (throw-if (nil? task) (str "No task named " name))
- (doto task
- (.init)
- (.setProject project)
- (set-properties! props))
- task))
-; END: safe-instantiate-task
-
View
23 lancet/step_3.clj
@@ -1,23 +0,0 @@
-(defn runonce
- "Create a function that will only run once. All other invocations
- return the first calculated value. The function can have side effects.
- Returns a [has-run-predicate, reset-fn, once-fn]"
- [function]
- (let [sentinel (Object.)
- result (atom sentinel)
- reset-fn (fn [] (reset! result sentinel))
- has-run? #(not= @result sentinel)]
- [has-run?
- reset-fn
- (fn [& args]
- (locking sentinel
- (if (= @result sentinel)
- (reset! result (function))
- @result)))]))
-
-
-
-
-
-
-
View
28 lancet/step_3_complete.clj
@@ -1,28 +0,0 @@
-(ns lancet.step-3-complete)
-
-; START: runonce
-(defn runonce
- "Create a function that will only run once. All other invocations
- return the first calculated value. The function can have side effects.
- Returns a [has-run-predicate, reset-fn, once-fn]"
- [function]
- (let [sentinel (Object.)
- result (atom sentinel)
- reset-fn (fn [] (reset! result sentinel) nil) ; <label id="concurrency.lancet.reset-fn"/>
- has-run? #(not= @result sentinel)] ; <label id="concurrency.lancet.has-run"/>
- [has-run?
- reset-fn
- (fn [& args]
- (locking sentinel
- (if (= @result sentinel)
- (reset! result (function))
- @result)))]))
-; END: runonce
-
-
-
-
-
-
-
-
View
19 lancet/step_3_repl.clj
@@ -1,19 +0,0 @@
-(ns lancet.step-3-repl)
-
-; START: create-runonce
-(defn create-runonce [function]
- (let [sentinel (Object.) ; <label id="concurrency.lancet.sentinel"/>
- result (atom sentinel)] ; <label id="concurrency.lancet.atom"/>
- (fn [& args]
- (locking sentinel ; <label id="concurrency.lancet.locking"/>
- (if (= @result sentinel)
- (reset! result (function)) ; <label id="concurrency.lancet.call"/>
- @result))))) ; <label id="concurrency.lancet.cache"/>
-; END: create-runonce
-
-
-
-
-
-
-
View
39 lancet/step_4_complete.clj
@@ -1,39 +0,0 @@
-(ns lancet.step-4-complete
- (:use [clojure.contrib.except :only (throw-if)]
- lancet.step-2-complete lancet.step-3-complete))
-
-(defmacro has-run? [f]
- `((:has-run-fn (meta (var ~f)))))
-
-(defmacro reset [f]
- `((:reset-fn (meta (var ~f)))))
-
-(defmacro deftarget [sym doc & forms]
- (let [has-run-fn (gensym "hr-") reset-fn (gensym "rf-")]
- `(let [[~has-run-fn ~reset-fn once-fn#] (runonce (fn [] ~@forms))]
- (def ~(with-meta
- sym
- {:doc doc :has-run-fn has-run-fn :reset-fn reset-fn})
- once-fn#))))
-
-(defmacro define-ant-task [clj-name ant-name]
- `(defn ~clj-name [props#]
- (let [task#
- (instantiate-task ant-project ~(name ant-name) props#)]
- (.execute task#)
- task#)))
-
-(defn task-names []
- (map symbol (sort (.. ant-project getTaskDefinitions keySet))))
-
-(defn safe-ant-name [n]
- (if (resolve n) (symbol (str "ant-" n)) n))
-
-(defmacro define-all-ant-tasks []
- `(do ~@(map (fn [n] `(define-ant-task ~(safe-ant-name n) ~n))
- (task-names))))
-
-(define-all-ant-tasks)
-
-
-
View
63 lancet/step_4_repl.clj
@@ -1,63 +0,0 @@
-(ns lancet.step-4-repl)
-; START: use
-(use 'lancet.step-2-complete 'lancet.step-3-complete)
-; END: use
-
-; START: has-run-fn
-(defn has-run? [v]
- ((:has-run-fn (meta v))))
-; END: has-run-fn
-
-(def has-run-fn has-run?)
-
-; START: has-run-macro
-(defmacro has-run? [f]
- `((:has-run-fn (meta (var ~f)))))
-; END: has-run-macro
-
-; START: reset
-(defmacro reset [f]
- `((:reset-fn (meta (var ~f)))))
-; END: reset
-
-; START: deftarget
-(defmacro deftarget [sym doc & forms]
- (let [has-run-fn (gensym "hr-") reset-fn (gensym "rf-")]
- `(let [[~has-run-fn ~reset-fn once-fn#] (runonce (fn [] ~@forms))]
- (def ~(with-meta
- sym
- {:doc doc :has-run-fn has-run-fn :reset-fn reset-fn})
- once-fn#))))
-; END: deftarget
-
-; START: define-ant-task
-(defmacro define-ant-task [clj-name ant-name]
- `(defn ~clj-name [props#]
- (let [task# (instantiate-task ant-project ~(name ant-name) props#)]
- (.execute task#)
- task#)))
-; END: define-ant-task
-
-; START: task-names
-(defn task-names []
- (map symbol (sort (.. ant-project getTaskDefinitions keySet))))
-; END: task-names
-
-; START: safe-ant-name
-(defn safe-ant-name [n]
- (if (resolve n) (symbol (str "ant-" n)) n))
-; END: safe-ant-name
-
-; START: define-all-ant-tasks
-(defmacro define-all-ant-tasks []
- `(do ~@(map (fn [n] `(define-ant-task ~n ~n)) (task-names))))
-; END: define-all-ant-tasks
-
-; START: safe-define-all-ant-tasks
-(defmacro define-all-ant-tasks []
- `(do ~@(map (fn [n] `(define-ant-task ~(safe-ant-name n) ~n)) (task-names))))
-; END: safe-define-all-ant-tasks
-
-(define-all-ant-tasks)
-
-
View
57 lancet/step_5_complete.clj
@@ -1,57 +0,0 @@
-(ns lancet.step-5-complete
- (:use clojure.contrib.except)
- (:import (java.beans Introspector)))
-
-(defmulti coerce
- (fn [dest-class src-inst] [dest-class (class src-inst)]))
-
-(defmethod coerce [java.io.File String] [_ str]
- (java.io.File. str))
-
-(defmethod coerce [Boolean/TYPE String] [_ str]
- (contains? #{"on" "yes" "true"} (.toLowerCase str)))
-
-(defmethod coerce :default [dest-cls obj] (cast dest-cls obj))
-
-(def
- #^{:doc "Dummy ant project to keep Ant tasks happy"}
- ant-project
- (let [proj (org.apache.tools.ant.Project.)
- logger (org.apache.tools.ant.NoBannerLogger.)]
- (doto logger
- (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
- (.setOutputPrintStream System/out)
- (.setErrorPrintStream System/err))
- (doto proj
- (.init)
- (.addBuildListener logger))))
-
-(defn property-descriptor [inst prop-name]
- (first
- (filter #(= (name prop-name) (.getName %))
- (.getPropertyDescriptors
- (Introspector/getBeanInfo (class inst))))))
-
-(defn get-property-class [write-method]
- (first (.getParameterTypes write-method)))
-
-(defn set-property! [inst prop value]
- (let [pd (property-descriptor inst prop)]
- (throw-if (nil? pd) (str "No such property " prop))
- (let [write-method (.getWriteMethod pd)
- dest-class (get-property-class write-method)]
- (.invoke
- write-method inst (into-array [(coerce dest-class value)])))))
-
-(defn set-properties! [inst prop-map]
- (doseq [[k v] prop-map] (set-property! inst k v)))
-
-(defn instantiate-task [project name props]
- (let [task (.createTask project name)]
- (throw-if (nil? task) (str "No task named " name))
- (doto task
- (.init)
- (.setProject project)
- (set-properties! props))))
-
-