• Leiningen is for automating Clojure
projects without setting your hair on fire.
• ⾯面向Clojure的构建⼯工具
• https://github.com/technomancy/leiningen
• http://clojars.org/
Leiningen
13年6月2⽇日星期⽇日
Slide 15
Slide 15 text
第⼀一个Clojure⼯工程
• $ lein new demo
• $ cd demo && lein deps && lein pom
• 将⼯工程导⼊入到IDEA
13年6月2⽇日星期⽇日
cont.
• (def a ‘(1 2)) => (1 2)
• (def b (cons 0 a)) => (0 1 2)
13年6月2⽇日星期⽇日
Slide 29
Slide 29 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 30
Slide 30 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 31
Slide 31 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 32
Slide 32 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 33
Slide 33 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 34
Slide 34 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 35
Slide 35 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 36
Slide 36 text
集合和Seq操作
13年6月2⽇日星期⽇日
Slide 37
Slide 37 text
forms
• When a list is used to perform an
operation, it is called a form.
• forms
• 函数
• 宏
• special forms (built-in forms)
13年6月2⽇日星期⽇日
Slide 38
Slide 38 text
special forms
• (def symbol a)
• 定义全局变量
• (do exprs*)
• 顺序求值表达式
• (if test then else)
• 条件语句
• (fn name? [params* ]
exprs*)
• 定义函数
• (let [bindings* ]
exprs*)
• 绑定值和变量
• var,loop,recur,try,thro
w ...
13年6月2⽇日星期⽇日
loop 和 recur
• Clojure没有专⻔门的循环结构,通过递归实
现
• loop + recur
• loop 建⽴立递归点,recur跳转到递归点
1. recur in other than a tail position is an error
2. recur is the only non-stack-consuming looping
construct in Clojure
3.recur is functional and its use in tail-position is
verified by the compiler.
13年6月2⽇日星期⽇日