7. Clojure 眼见为实
• 顺序
(do (println 1) (println 2) ……)
• 条件
(if (> a b)
“a大于b”
“b大于或者等于a”)
• 循环
(loop [n 1 ret 0]
(if (> n 100)
ret
(recur (inc n) (+ ret n))))
7
8. Clojure 眼见为实
•(+ a b c d) => a +b + c + d
•(* a (+ b c) d) => a * (b + c) * d
•(op arg1 arg2 ……)
List 数据结构
8
9. Clojure 眼见为实
• Code <=> Data
• List 结构:中间代码,宏可以操作并生成中
间代码
• 宏(Macro):扩展编译器,加入新的语法结
构。
9
if test
then
else
when test
something1
something2
……
(defmacro when
[test & body]
(list 'if test (cons 'do body)))
27. Test
• Unit test: clojure.test & ring-mock
• lein test
• clojure-test-mode
• We just test normal functions
• Integration test:
• clj-webdriver
• Ruby watirwebdriver etc.
27
28. Build/Deploy
• Build
• lein uberjar
• lein ring war
• lein jar + libdir plugin
• Web Container:
• jetty
• http-kit
• Immutant(JBoss)
28
37. At the end
• Book:
• 《Clojure Programming》
• 《Clojure in Action》
• 《The Joy of Clojure》
• Community:
• Clojure User Group
• China Clojure User Group
37