├── .gitignore ├── image └── clojure-icon.gif ├── clojure.data ├── index.rst └── diff.rst ├── clojure.test ├── index.rst └── are.rst ├── clojure.xml ├── index.rst └── parse.rst ├── clojure.core.async ├── index.rst └── buffer.rst ├── fixed_width_pyramid ├── static │ ├── footerbg.png │ ├── headerbg.png │ ├── middlebg.png │ ├── dialog-note.png │ ├── dialog-todo.png │ ├── dialog-topic.png │ ├── transparent.gif │ ├── dialog-seealso.png │ ├── dialog-warning.png │ ├── ie6.css │ ├── epub.css │ └── pyramid.css_t ├── theme.conf ├── disqus.html └── layout.html ├── clojure.java.browse ├── index.rst └── browse-url.rst ├── clojure.pprint ├── pp.rst ├── index.rst └── cl-format.rst ├── clojure.java.io ├── default-streams-impl.rst ├── Coercions.rst ├── IOFactory.rst ├── make-parents.rst ├── resource.rst ├── index.rst ├── reader.rst ├── make-reader.rst ├── as-relative-path.rst ├── writer.rst ├── make-writer.rst ├── as-file.rst ├── delete-file.rst ├── as-url.rst ├── file.rst ├── input-stream.rst ├── copy.rst ├── output-stream.rst ├── make-output-stream.rst └── make-input-stream.rst ├── clojure.core ├── key.rst ├── even.rst ├── reverse.rst ├── odd.rst ├── zipmap.rst ├── alength.rst ├── shuffle.rst ├── defprotocol.rst ├── into.rst ├── distinct.rst ├── keys.rst ├── vals.rst ├── merge.rst ├── re-seq.rst ├── cons.rst ├── delay_p.rst ├── empty.rst ├── compile.rst ├── defn-.rst ├── aclone.rst ├── bigint.rst ├── doseq.rst ├── constantly.rst ├── biginteger.rst ├── mapcat.rst ├── when-let.rst ├── next.rst ├── complement.rst ├── sort.rst ├── when-not.rst ├── comp.rst ├── declare.rst ├── first.rst ├── time.rst ├── bigdec.rst ├── alter-var-root.rst ├── count.rst ├── if-not.rst ├── doall.rst ├── realized.rst ├── counted.rst ├── pcalls.rst ├── remove.rst ├── filter.rst ├── iterate.rst ├── keep-indexed.rst ├── pvalues.rst ├── comment.rst ├── keep.rst ├── max-key.rst ├── min-key.rst ├── map-indexed.rst ├── get.rst ├── defonce.rst ├── with-open.rst ├── if-let.rst ├── some.rst ├── cond.rst ├── contains.rst ├── reductions.rst ├── seq.rst ├── dorun.rst ├── repeat.rst ├── concat.rst ├── tree-seq.rst ├── rsubseq.rst ├── delay.rst ├── conj.rst ├── dissoc.rst ├── import.rst ├── future.rst ├── problem-of-pcalls-and-pvalues.rst ├── pmap.rst ├── reduce.rst ├── rseq.rst ├── line-seq.rst ├── subseq.rst ├── assoc.rst ├── partial.rst ├── letfn.rst ├── ->>.rst ├── -__.rst ├── range.rst ├── deref.rst ├── map.rst ├── promise.rst ├── ->.rst ├── -_.rst ├── fn.rst ├── index.rst ├── xml-seq.rst ├── repeatedly.rst └── file-seq.rst ├── clojure.java.shell ├── index.rst ├── with-sh-dir.rst ├── with-sh-env.rst └── sh.rst ├── clojure.repl ├── index.rst ├── apropos.rst ├── dir.rst ├── dir-fn.rst ├── find-doc.rst ├── doc.rst └── pst.rst ├── clojure.string ├── reverse.rst ├── triml.rst ├── trimr.rst ├── trim.rst ├── lower-case.rst ├── upper-case.rst ├── capitalize.rst ├── replace-first.rst ├── blank.rst ├── index.rst ├── escape.rst ├── join.rst ├── split-lines.rst ├── trim-newline.rst ├── replace.rst └── split.rst ├── clojure.java.javadoc ├── index.rst ├── add-local-javadoc.rst ├── javadoc.rst └── add-remote-javadoc.rst ├── clojure.set ├── ind.rst ├── intersection.rst ├── union.rst ├── subset_q.rst ├── superset_q.rst ├── rename.rst ├── select.rst ├── map-invert.rst ├── rename-keys.rst ├── project.rst ├── difference.rst ├── join.rst └── index.rst ├── index.rst ├── README.rst ├── make.bat ├── Makefile └── conf.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | _build/ 3 | -------------------------------------------------------------------------------- /image/clojure-icon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/image/clojure-icon.gif -------------------------------------------------------------------------------- /clojure.data/index.rst: -------------------------------------------------------------------------------- 1 | clojure.data 2 | ============== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | diff 8 | -------------------------------------------------------------------------------- /clojure.test/index.rst: -------------------------------------------------------------------------------- 1 | clojure.test 2 | ================ 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | are 8 | -------------------------------------------------------------------------------- /clojure.xml/index.rst: -------------------------------------------------------------------------------- 1 | clojure.xml 2 | ===================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | parse 8 | -------------------------------------------------------------------------------- /clojure.core.async/index.rst: -------------------------------------------------------------------------------- 1 | clojure.core.async 2 | ==================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | buffer 8 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/footerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/footerbg.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/headerbg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/headerbg.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/middlebg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/middlebg.png -------------------------------------------------------------------------------- /clojure.java.browse/index.rst: -------------------------------------------------------------------------------- 1 | clojure.java.browse 2 | ======================= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | browse-url 8 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/dialog-note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/dialog-note.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/dialog-todo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/dialog-todo.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/dialog-topic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/dialog-topic.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/transparent.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/transparent.gif -------------------------------------------------------------------------------- /fixed_width_pyramid/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = pyramid.css 4 | pygments_style = sphinx.pygments_styles.PyramidStyle 5 | -------------------------------------------------------------------------------- /clojure.pprint/pp.rst: -------------------------------------------------------------------------------- 1 | pp 2 | ============ 3 | 4 | | **(macro)** 5 | 6 | 使用宏去调用 pprint 打印上一次的输出。等价于 ``(pprint *1)`` 。 7 | 8 | 添加于 Clojure 1.2 版本。 9 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/dialog-seealso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/dialog-seealso.png -------------------------------------------------------------------------------- /fixed_width_pyramid/static/dialog-warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/huangzworks/clojure_api_cn/HEAD/fixed_width_pyramid/static/dialog-warning.png -------------------------------------------------------------------------------- /clojure.java.io/default-streams-impl.rst: -------------------------------------------------------------------------------- 1 | default-streams-impl 2 | ==================== 3 | 4 | 5 | ``IOFactory`` 的默认实现,抛出 ``IllegalArgumentException`` 。 6 | -------------------------------------------------------------------------------- /clojure.core/key.rst: -------------------------------------------------------------------------------- 1 | key 2 | --------------- 3 | 4 | **(key e)** 5 | 6 | 返回map的键集合 7 | 8 | :: 9 | (map key {:a 1,:b 2}) 10 | (:a :b) 11 | 12 | -------------------------------------------------------------------------------- /clojure.java.io/Coercions.rst: -------------------------------------------------------------------------------- 1 | Coercions 2 | ============= 3 | 4 | ``clojure.java.io`` 内部定义的protocol,有 ``as-file`` 和 ``as-url`` 两个方法,clojure为多种类型实现了这个protocol。 5 | -------------------------------------------------------------------------------- /clojure.java.shell/index.rst: -------------------------------------------------------------------------------- 1 | clojure.java.shell 2 | ================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | sh 8 | 9 | with-sh-dir 10 | 11 | with-sh-env 12 | 13 | -------------------------------------------------------------------------------- /clojure.repl/index.rst: -------------------------------------------------------------------------------- 1 | clojure.repl 2 | ===================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | apropos 8 | dir 9 | dir-fn 10 | doc 11 | find-doc 12 | pst 13 | -------------------------------------------------------------------------------- /clojure.core/even.rst: -------------------------------------------------------------------------------- 1 | even? 2 | --------------- 3 | 4 | **(even? n)** 5 | 6 | 当n是偶数时返回true,如果n不是一个整数则抛出异常 7 | 8 | :: 9 | 10 | (even? 2) 11 | true 12 | (even? 1) 13 | false 14 | -------------------------------------------------------------------------------- /clojure.string/reverse.rst: -------------------------------------------------------------------------------- 1 | reverse 2 | ---------- 3 | 4 | **(reverse s)** 5 | 6 | 返回字符串 ``s`` 的逆序版本。 7 | 8 | :: 9 | 10 | user=> (clojure.string/reverse "clojure") 11 | "erujolc" 12 | 13 | -------------------------------------------------------------------------------- /clojure.string/triml.rst: -------------------------------------------------------------------------------- 1 | triml 2 | ------- 3 | 4 | **(triml s)** 5 | 6 | 移除字符串 ``s`` 左端的空白。 7 | 8 | :: 9 | 10 | user=> (clojure.string/triml " clojure ") 11 | "clojure " 12 | 13 | -------------------------------------------------------------------------------- /clojure.string/trimr.rst: -------------------------------------------------------------------------------- 1 | trimr 2 | ------ 3 | 4 | **(trimr s)** 5 | 6 | 移除字符串 ``s`` 右端的空白。 7 | 8 | :: 9 | 10 | user=> (clojure.string/trimr " clojure ") 11 | " clojure" 12 | 13 | -------------------------------------------------------------------------------- /clojure.core/reverse.rst: -------------------------------------------------------------------------------- 1 | reverse 2 | ----------- 3 | 4 | **(reverse coll)** 5 | 6 | 逆序给定的 ``coll`` 。 7 | 8 | 这个操作不是惰性(lazy)的。 9 | 10 | :: 11 | 12 | (user=>(reverse [1 2 3 4]) 13 | (4 3 2 1) 14 | -------------------------------------------------------------------------------- /clojure.core.async/buffer.rst: -------------------------------------------------------------------------------- 1 | buffer 2 | --------------- 3 | 4 | **(buffer n)** 5 | 6 | 返回一个大小固定为n的buffer,当buffer满了的时候,put操作会阻塞 7 | 8 | :: 9 | 10 | user=> (def c (chan (buffer 3))) 11 | #'user/c 12 | -------------------------------------------------------------------------------- /clojure.core/odd.rst: -------------------------------------------------------------------------------- 1 | odd? 2 | --------------- 3 | 4 | **(odd? n)** 5 | 6 | 当n是奇数时返回true,如果n不是一个整数则抛出异常 7 | 8 | :: 9 | 10 | (odd? 1) 11 | true 12 | (odd? 2) 13 | false 14 | (odd? 0) 15 | false 16 | -------------------------------------------------------------------------------- /clojure.core/zipmap.rst: -------------------------------------------------------------------------------- 1 | zipmap 2 | --------------- 3 | 4 | **(zipmap keys vals)** 5 | 6 | 返回一个含有键和相应值的map 7 | 8 | :: 9 | 10 | user=> (zipmap [:a :b :c :d :e] [1 2 3 4 5]) 11 | {:e 5, :d 4, :c 3, :b 2, :a 1} 12 | -------------------------------------------------------------------------------- /clojure.java.javadoc/index.rst: -------------------------------------------------------------------------------- 1 | clojure.java.javadoc 2 | ========================= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | add-local-javadoc 8 | 9 | add-remote-javadoc 10 | 11 | javadoc 12 | 13 | -------------------------------------------------------------------------------- /clojure.string/trim.rst: -------------------------------------------------------------------------------- 1 | trim 2 | ----- 3 | 4 | 从字符串的两端移除空白。 5 | 6 | :: 7 | 8 | user=> (clojure.string/trim "clojure") 9 | "clojure" 10 | 11 | user=> (clojure.string/trim " clojure ") 12 | "clojure" 13 | 14 | -------------------------------------------------------------------------------- /clojure.core/alength.rst: -------------------------------------------------------------------------------- 1 | alength 2 | -------- 3 | 4 | **(alength array)** 5 | 6 | 返回Java数组长度,作用于所有类型 7 | 8 | :: 9 | 10 | (def array (into-array Integer/TYPE [1 2 3 4 5])) 11 | #'user/array 12 | 13 | (alength array) 14 | 5 15 | -------------------------------------------------------------------------------- /clojure.core/shuffle.rst: -------------------------------------------------------------------------------- 1 | shuffle 2 | ----------- 3 | 4 | **(shuffle coll)** 5 | 6 | 返回对 ``coll`` 进行乱序排列之后得出的序列。 7 | 8 | :: 9 | 10 | user=> (shuffle [1 2 3 4]) 11 | [4 1 3 2] 12 | 13 | user=> (shuffle [1 2 3 4]) 14 | [1 3 2 4] 15 | 16 | 17 | -------------------------------------------------------------------------------- /clojure.core/defprotocol.rst: -------------------------------------------------------------------------------- 1 | defprotocol 2 | -------------- 3 | 4 | **(defprotocol name & opts+sigs)** 5 | 6 | 协议是一组命名方法和签名 7 | 8 | :: 9 | 10 | (defprotocol IOFactory 11 | (make-reader [this] "Create a Buffered Reader") 12 | (make-writer [this] "Create a Buffered Writer") 13 | ) 14 | -------------------------------------------------------------------------------- /clojure.java.shell/with-sh-dir.rst: -------------------------------------------------------------------------------- 1 | with-sh-dir 2 | ============== 3 | 4 | **(with-sh-dir dir & forms)** 5 | 6 | 设置 ``sh`` 函数所使用的目录, 7 | 详情请参见 :ref:`sh 函数的文档 ` 。 8 | 9 | `查看源码 `_ 10 | -------------------------------------------------------------------------------- /clojure.java.javadoc/add-local-javadoc.rst: -------------------------------------------------------------------------------- 1 | add-local-javadoc 2 | ==================== 3 | 4 | **(add-local-javadoc path)** 5 | 6 | 将路径 ``path`` 添加到本地 javadoc 的路径列表中。 7 | 8 | `查看源码 `_ 9 | 10 | -------------------------------------------------------------------------------- /clojure.string/lower-case.rst: -------------------------------------------------------------------------------- 1 | lower-case 2 | --------------- 3 | 4 | **(lower-case s)** 5 | 6 | 将字符串 ``s`` 的所有字符转换为小写。 7 | 8 | :: 9 | 10 | user=> (clojure.string/lower-case "hello moto") 11 | "hello moto" 12 | 13 | user=> (clojure.string/lower-case "HELLO MOTO") 14 | "hello moto" 15 | 16 | -------------------------------------------------------------------------------- /clojure.string/upper-case.rst: -------------------------------------------------------------------------------- 1 | upper-case 2 | ------------- 3 | 4 | **(upper-case s)** 5 | 6 | 将字符串 ``s`` 的所有字符转换为大写。 7 | 8 | :: 9 | 10 | user=> (clojure.string/upper-case "hello moto") 11 | "HELLO MOTO" 12 | 13 | user=> (clojure.string/upper-case "HELLO MOTO") 14 | "HELLO MOTO" 15 | 16 | -------------------------------------------------------------------------------- /clojure.core/into.rst: -------------------------------------------------------------------------------- 1 | into 2 | --------------- 3 | 4 | **(into to from)** 5 | 6 | 将from-coll中的所有元素合并至to-coll并返回结果 7 | 8 | :: 9 | 10 | user=> (into (sorted-map) [ [:a 1] [:c 3] [:b 2] ] ) 11 | {:a 1, :b 2, :c 3} 12 | user=> (into (sorted-map) [ {:a 1} {:c 3} {:b 2} ] ) 13 | {:a 1, :b 2, :c 3} 14 | -------------------------------------------------------------------------------- /clojure.java.io/IOFactory.rst: -------------------------------------------------------------------------------- 1 | IOFactory 2 | =========== 3 | 4 | ``clojure.java.io`` 内部定义的protocol,包含 ``make-reader`` , ``make-writer`` , ``make-input-stream`` 和 ``make-out-stream`` 四个方法。这四个方法创建的都是带缓冲区的reader,writer或stream。 5 | 6 | 用户应该避免直接使用上述四个API,而是使用 ``reader`` , ``writer`` , ``input-stream`` 和 ``output-stream`` 。 7 | -------------------------------------------------------------------------------- /clojure.core/distinct.rst: -------------------------------------------------------------------------------- 1 | distinct 2 | ---------- 3 | 4 | **(distinct coll)** 5 | 6 | 给定一个 ``coll`` ,返回一个无重复元素的惰性序列。 7 | 8 | :: 9 | 10 | ; 有重复元素的向量 11 | 12 | user=> (distinct [1 2 1 2]) 13 | (1 2) 14 | 15 | 16 | ; 无重复元素的向量 17 | 18 | user=> (distinct [1 2 3 4]) 19 | (1 2 3 4) 20 | 21 | 22 | -------------------------------------------------------------------------------- /clojure.string/capitalize.rst: -------------------------------------------------------------------------------- 1 | capitalize 2 | ----------- 3 | 4 | **(capitalize s)** 5 | 6 | 将字符串 ``s`` 的首个字符转换成大写,剩余的其他字符全部转换为小写。 7 | 8 | :: 9 | 10 | user=> (clojure.string/capitalize "hello world") 11 | "Hello world" 12 | 13 | user=> (clojure.string/capitalize "HELLO WORLD") 14 | "Hello world" 15 | 16 | -------------------------------------------------------------------------------- /clojure.core/keys.rst: -------------------------------------------------------------------------------- 1 | keys 2 | --------- 3 | 4 | **(keys map)** 5 | 6 | 返回一个序列,序列里包含给定 ``map`` 的所有键(key)。 7 | 8 | :: 9 | 10 | ; 空 Map 11 | 12 | user=> (keys {}) 13 | nil 14 | 15 | ; 非空 Map 16 | 17 | user=> (keys {:python "Guido" :clojure "Rich" :ruby "Matz"}) 18 | (:python :ruby :clojure) 19 | 20 | 21 | -------------------------------------------------------------------------------- /clojure.core/vals.rst: -------------------------------------------------------------------------------- 1 | vals 2 | --------- 3 | 4 | **(vals map)** 5 | 6 | 返回一个序列,序列里包含给定 ``map`` 的所有值(value)。 7 | 8 | :: 9 | 10 | ; 空 Map 11 | 12 | user=> (vals {}) 13 | nil 14 | 15 | ; 非空 Map 16 | 17 | user=> (vals {:python "Guido" :clojure "Rich" :ruby "Matz"}) 18 | ("Guido" "Matz" "Rich") 19 | 20 | 21 | -------------------------------------------------------------------------------- /clojure.java.shell/with-sh-env.rst: -------------------------------------------------------------------------------- 1 | with-sh-env 2 | ============== 3 | 4 | **(with-sh-env env & forms)** 5 | 6 | 设置 ``sh`` 函数所使用的环境变量, 7 | 详情请参见 :ref:`sh 函数的文档 ` 。 8 | 9 | `查看源码 `_ 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /clojure.core/merge.rst: -------------------------------------------------------------------------------- 1 | merge 2 | -------- 3 | 4 | **(merge & maps)** 5 | 6 | 返回一个含有剩余项的map。 7 | 如果key在多个map中存在,后面的值(从左向右的顺序)会覆盖前面的值 8 | 9 | :: 10 | user=> (merge {:a 1 :b 2 :c 3} {:b 9 :d 4}) 11 | {:d 4, :a 1, :b 9, :c 3} 12 | 13 | user=> (merge {:a 1 :b 2 :c 3} {:b 9 :d 4} {:b 8 :d 3}) 14 | {:d 3, :c 3, :b 8, :a 1} 15 | -------------------------------------------------------------------------------- /clojure.core/re-seq.rst: -------------------------------------------------------------------------------- 1 | re-seq 2 | ----------- 3 | 4 | **(re-seq re s)** 5 | 6 | 返回一个惰性序列, 7 | 序列里包含字符串 ``s`` 中所有匹配模式 ``re`` 的值, 8 | 匹配使用 ``java.util.regex.Matcher.find()`` 进行, 9 | 每个匹配值都经过 ``re-groups`` 处理。 10 | 11 | :: 12 | 13 | ; 查找字符串中的所有数字值 14 | 15 | user=> (re-seq #"[0-9]+" "abs123def345ghi567") 16 | ("123" "345" "567") 17 | -------------------------------------------------------------------------------- /clojure.core/cons.rst: -------------------------------------------------------------------------------- 1 | cons 2 | --------- 3 | 4 | **(cons x seq)** 5 | 6 | 返回一个新的序列, 7 | 序列的第一个元素是 ``x`` , 8 | 而 ``seq`` 则是序列的其余部分。 9 | 10 | :: 11 | 12 | ; cons 起数字 1 和空列表 13 | 14 | user=> (cons 1 '()) 15 | (1) 16 | 17 | 18 | ; cons 起数字 1 和列表 (2 3) 19 | 20 | user=> (cons 1 (list 2 3)) 21 | (1 2 3) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /clojure.string/replace-first.rst: -------------------------------------------------------------------------------- 1 | replace-first 2 | ---------------- 3 | 4 | **(replace-first s match replacement)** 5 | 6 | 和 `replace` 函数的作用类似,但只替换 ``match`` 的第一个实例。 7 | 8 | :: 9 | 10 | ; 只有第一个匹配的原音 e 被转为大写字母了 11 | 12 | user=> (clojure.string/replace-first "The color is red" #"[aeiou]" clojure.string/upper-case) 13 | "ThE color is red" 14 | 15 | -------------------------------------------------------------------------------- /clojure.core/delay_p.rst: -------------------------------------------------------------------------------- 1 | delay? 2 | ======= 3 | 4 | **(delay? x)** 5 | 6 | 如果 ``x`` 是用 ``delay`` 创建的一个 ``Delay`` 对象,那么返回 ``true`` 。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (delay? 2) 13 | false 14 | 15 | user=> (delay? (delay)) 16 | true 17 | -------------------------------------------------------------------------------- /clojure.set/ind.rst: -------------------------------------------------------------------------------- 1 | clojure.set 2 | ================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | difference 8 | 9 | index 10 | 11 | intersection 12 | 13 | join 14 | 15 | map-invert 16 | 17 | project 18 | 19 | rename 20 | 21 | rename-keys 22 | 23 | select 24 | 25 | subset_q 26 | 27 | superset_q 28 | 29 | union 30 | -------------------------------------------------------------------------------- /clojure.test/are.rst: -------------------------------------------------------------------------------- 1 | are 2 | ===== 3 | macro 4 | 5 | | **(are argv expr & args)** 6 | 7 | 通过以模板表达的方式检查多个断言(``assertions``)。关于模板的解释请查阅 ``clojure.template/do-template`` 8 | 9 | :: 10 | 11 | ;例子: 12 | (are [x y] (= x y) 13 | 2 (+ 1 1) 14 | 4 (* 2 2)) 15 | 16 | ;宏将展开为: 17 | (do (is (= 2 (+ 1 1))) 18 | (is (= 4 (* 2 2)))) 19 | -------------------------------------------------------------------------------- /clojure.core/empty.rst: -------------------------------------------------------------------------------- 1 | empty? 2 | ---------- 3 | 4 | **(empty? coll)** 5 | 6 | 如果 ``coll`` 中不包含任何元素,那么返回 ``true`` , 7 | 效果等同于执行 ``(not (seq coll))`` 。 8 | 9 | 请使用惯用法 ``(seq x)`` 代替 ``(not (empty? x))`` 。 10 | 11 | :: 12 | 13 | user=> (empty? '()) 14 | true 15 | 16 | user=> (empty? nil) 17 | true 18 | 19 | user=> (empty? [1 2 3]) 20 | false 21 | 22 | 23 | -------------------------------------------------------------------------------- /clojure.java.browse/browse-url.rst: -------------------------------------------------------------------------------- 1 | browse-url 2 | =============== 3 | 4 | **(browse-url url)** 5 | 6 | 在浏览器中打开地址 ``url`` 。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (use 'clojure.java.browse) 13 | 14 | user=> (browse-url "http://clojuredocs.org") 15 | -------------------------------------------------------------------------------- /clojure.core/compile.rst: -------------------------------------------------------------------------------- 1 | compile 2 | -------- 3 | 4 | **(compile lib)** 5 | 6 | 编译符号(symbol) ``lib`` 定义的命名空间到一系列的class文件。 ``lib`` 的源文件必须在正确的类关联(classpath-relative)的目录下,输出的文class文件将会在 ``*compile-path*`` 定义的目录里,这个目录也必须在类路径(classpath)里面。 7 | 8 | 9 | `查看源码 `_ 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /clojure.core/defn-.rst: -------------------------------------------------------------------------------- 1 | defn- 2 | --------------- 3 | 4 | **(defn- name & decls)** 5 | 6 | 作用和 ``defn`` 类似,唯一的不同是创建的函数是私有的。 7 | 8 | :: 9 | 10 | user=> (defn- msg [] "hello moto") 11 | #'user/msg 12 | 13 | user=> (msg) 14 | "hello moto" 15 | 16 | user=> (meta #'msg) 17 | {:arglists ([]), :ns #, :name msg, :private true, :line 1, :file "NO_SOURCE_PATH"} 18 | -------------------------------------------------------------------------------- /clojure.core/aclone.rst: -------------------------------------------------------------------------------- 1 | aclone 2 | -------- 3 | 4 | **(aclone array)** 5 | 6 | 返回Java数组的克隆,作用于已知类型的数组 7 | 8 | :: 9 | 10 | user=> (def a (int-array [1 2 3 4])) 11 | #'user/a 12 | 13 | user=> (def b (aclone a)) 14 | #'user/b 15 | 16 | user=> (aset b 0 23) 17 | 23 18 | 19 | user=> (vec b) 20 | [23 2 3 4] 21 | 22 | user=> (vec a) 23 | [1 2 3 4] 24 | -------------------------------------------------------------------------------- /clojure.core/bigint.rst: -------------------------------------------------------------------------------- 1 | bigint 2 | -------- 3 | 4 | **(bigint x)** 5 | 6 | 7 | 将 ``x`` 强制转换为 ``BigInt`` 。 8 | 9 | `查看源码 `_ 10 | 11 | 12 | :: 13 | 14 | user=> (def x (biginteger 19931029)) 15 | #'user/x 16 | 17 | user=> (class x) 18 | java.math.BigInteger 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /clojure.core/doseq.rst: -------------------------------------------------------------------------------- 1 | doseq 2 | ---------- 3 | 4 | | **(doseq seq-exprs & body)** 5 | 6 | 使用和 ``for`` 宏一样的绑定和过滤器,反复执行 ``body`` (通常是为了产生副作用)。 7 | 8 | 返回 ``nil`` 而不是序列的首元素作为函数结果。 9 | 10 | 自 Clojure 1.0 版本以来可用。 11 | 12 | :: 13 | 14 | user=> (doseq [i (range 10)] (prn i)) 15 | 0 16 | 1 17 | 2 18 | 3 19 | 4 20 | 5 21 | 6 22 | 7 23 | 8 24 | 9 25 | nil 26 | -------------------------------------------------------------------------------- /clojure.core/constantly.rst: -------------------------------------------------------------------------------- 1 | constantly 2 | ------------ 3 | 4 | **(constantly x)** 5 | 6 | 返回一个匿名函数, 7 | 接受任何数量的参数, 8 | 但总是返回 ``x`` 。 9 | 10 | :: 11 | 12 | user=> (def ten (constantly 10)) 13 | #'user/ten 14 | 15 | user=> (ten) 16 | 10 17 | 18 | user=> (ten 1) 19 | 10 20 | 21 | user=> (ten 1 2) 22 | 10 23 | 24 | user=> (ten 1 2 3) 25 | 10 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /clojure.string/blank.rst: -------------------------------------------------------------------------------- 1 | blank? 2 | ------- 3 | 4 | **(blank? s)** 5 | 6 | 如果 ``s`` 是 ``nil`` 、空字符串 ``""`` 或者只包含空白的字符串,那么返回 ``true`` 。 7 | 8 | :: 9 | 10 | user=> (clojure.string/blank? nil) 11 | true 12 | 13 | user=> (clojure.string/blank? "") 14 | true 15 | 16 | user=> (clojure.string/blank? " ") 17 | true 18 | 19 | user=> (clojure.string/blank? "hello world") 20 | false 21 | -------------------------------------------------------------------------------- /clojure.core/biginteger.rst: -------------------------------------------------------------------------------- 1 | biginteger 2 | ------------------ 3 | 4 | **(biginteger x)** 5 | 6 | 7 | 将 ``x`` 强制转换为 ``BigInteger`` 。 8 | 9 | `查看源码 `_ 10 | 11 | 12 | :: 13 | 14 | user=> (def x (biginteger 19931029)) 15 | #'user/x 16 | 17 | user=> (class x) 18 | java.math.BigInteger 19 | 20 | 21 | -------------------------------------------------------------------------------- /clojure.core/mapcat.rst: -------------------------------------------------------------------------------- 1 | mapcat 2 | ======== 3 | 4 | **(mapcat f & colls)** 5 | 6 | 等同于调用 ``(concat (map f colls))`` 。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (mapcat reverse [[3 2 1 0] 13 | [6 5 4] 14 | [9 8 7]]) 15 | (0 1 2 3 4 5 6 7 8 9) 16 | 17 | -------------------------------------------------------------------------------- /clojure.core/when-let.rst: -------------------------------------------------------------------------------- 1 | when-let 2 | -------------- 3 | 4 | | **(when-let bindings & body)** 5 | | **bindings => binding-form test** 6 | 7 | 如果 ``test`` 的值 ``value`` 为真,那么结合 ``binding-form`` 绑定,对 ``body`` 进行求值。 8 | 9 | :: 10 | 11 | user=> (defn drop-one [coll] 12 | (when-let [s (seq coll)] 13 | (rest s))) 14 | #'user/drop-one 15 | 16 | user=> (drop-one [1 2 3]) 17 | (2 3) 18 | -------------------------------------------------------------------------------- /clojure.core/next.rst: -------------------------------------------------------------------------------- 1 | next 2 | -------- 3 | 4 | **(next coll)** 5 | 6 | 返回 ``coll`` 除了第一个元素之外,余下的其他全部元素。 7 | 8 | 传入的 ``coll`` 会被 ``seq`` 函数处理。 9 | 10 | 如果 ``coll`` 除了 ``(first coll)`` 之外, 11 | 没有其他别的元素,那么返回 ``nil`` 。 12 | 13 | :: 14 | 15 | user=> (next nil) 16 | nil 17 | 18 | user=> (next [1]) 19 | nil 20 | 21 | user=> (next [1 2]) 22 | (2) 23 | 24 | user=> (next [1 2 3]) 25 | (2 3) 26 | 27 | 28 | -------------------------------------------------------------------------------- /clojure.string/index.rst: -------------------------------------------------------------------------------- 1 | clojure.string 2 | ===================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | blank 8 | 9 | reverse 10 | 11 | escape 12 | 13 | replace 14 | 15 | replace-first 16 | 17 | capitalize 18 | 19 | lower-case 20 | 21 | upper-case 22 | 23 | join 24 | 25 | split 26 | 27 | split-lines 28 | 29 | trim 30 | 31 | triml 32 | 33 | trimr 34 | 35 | trim-newline 36 | -------------------------------------------------------------------------------- /clojure.core/complement.rst: -------------------------------------------------------------------------------- 1 | complement 2 | -------------- 3 | 4 | **(complement f)** 5 | 6 | 接受一个函数 ``f`` ,返回一个匿名函数。 7 | 8 | 这个匿名函数接受的参数、产生的作用都和 ``f`` 一样, 9 | 但它返回的真值和 ``f`` 相反。 10 | 11 | :: 12 | 13 | user=> (defn f [] 14 | (println "hello") 15 | false) 16 | #'user/f 17 | 18 | user=> (f) 19 | hello 20 | false 21 | 22 | user=> ((complement f)) 23 | hello 24 | true 25 | 26 | 27 | -------------------------------------------------------------------------------- /clojure.core/sort.rst: -------------------------------------------------------------------------------- 1 | sort 2 | ------- 3 | 4 | | **(sort coll)** 5 | | **(sort comparator coll)** 6 | 7 | 返回对 ``coll`` 进行排序之后得到的序列。 8 | 9 | 如果不指定 ``comparator`` , 10 | 那么默认使用 ``compare.`` , 11 | ``comparator`` 必须实现 ``java.util.Comparator`` 。 12 | 13 | :: 14 | 15 | user=> (sort [4 2 1 3]) 16 | (1 2 3 4) 17 | 18 | user=> (sort >= [4 2 1 3]) 19 | (4 3 2 1) 20 | 21 | user=> (sort <= [4 2 1 3]) 22 | (1 2 3 4) 23 | 24 | 25 | -------------------------------------------------------------------------------- /clojure.core/when-not.rst: -------------------------------------------------------------------------------- 1 | when-not 2 | ---------- 3 | 4 | **(when-not test & body)** 5 | 6 | 对 ``test`` 部分进行求值,如果结果为 ``false`` ,那么在一个隐式 ``do`` 的包围下对 ``body`` 进行求值。 7 | 8 | :: 9 | 10 | user=> (when-not true 11 | (println "hello") 12 | (println "moto")) 13 | nil 14 | 15 | user=> (when-not false 16 | (println "hello") 17 | (println "moto")) 18 | hello 19 | moto 20 | nil 21 | -------------------------------------------------------------------------------- /clojure.core/comp.rst: -------------------------------------------------------------------------------- 1 | comp 2 | ------- 3 | 4 | | **(comp)** 5 | | **(comp f)** 6 | | **(comp f g)** 7 | | **(comp f g h)** 8 | | **(comp f g h & other-functions)** 9 | 10 | ``comp`` 接受一系列函数作为输入, 11 | 返回一个匿名函数。 12 | 13 | 这个匿名函数接受可变数量的参数(variable number of args), 14 | 并按从右到左的顺序, 15 | 将传入的函数应用到参数中。 16 | 17 | :: 18 | 19 | user=> ((comp str double +) 3 3 3) ; 以下两个表达等价 20 | "9.0" 21 | 22 | user=> (str (double (+ 3 3 3))) 23 | "9.0" 24 | 25 | 26 | -------------------------------------------------------------------------------- /clojure.core/declare.rst: -------------------------------------------------------------------------------- 1 | declare 2 | ----------- 3 | 4 | **(declare & names)** 5 | 6 | 定义一些无绑定的 var 名字,用于提前声明(forward declarations)。 7 | 8 | :: 9 | 10 | user=> (defn f [] 11 | (g)) 12 | ;CompilerException java.lang.RuntimeException: Unable to resolve symbol: g in this context, compiling:(NO_SOURCE_PATH:2) 13 | 14 | user=> (declare g) 15 | #'user/g 16 | 17 | user=> (defn f [] 18 | (g)) 19 | #'user/f 20 | -------------------------------------------------------------------------------- /clojure.core/first.rst: -------------------------------------------------------------------------------- 1 | first 2 | --------- 3 | 4 | **(first coll)** 5 | 6 | 返回 ``coll`` 中的第一个元素。 7 | 8 | 传入的 ``coll`` 会被 ``seq`` 函数处理。 9 | 10 | 如果 ``coll`` 为 ``nil`` ,返回 ``nil`` 。 11 | 12 | :: 13 | 14 | user=> (first nil) 15 | nil 16 | 17 | user=> (first [1 2 3]) 18 | 1 19 | 20 | user=> (first (list 1 2 3)) 21 | 1 22 | 23 | user=> (first {:clojure "Rich" :python "Guido" :ruby "Matz"}) 24 | [:python "Guido"] 25 | 26 | 27 | -------------------------------------------------------------------------------- /clojure.core/time.rst: -------------------------------------------------------------------------------- 1 | time 2 | ------ 3 | 4 | **(time expr)** 5 | 6 | 对 ``expr`` 进行求值,并打印求值所花费的时间。 7 | 8 | ``expr`` 的值作为函数的返回值被返回。 9 | 10 | `查看源码 `_ 11 | 12 | :: 13 | 14 | ; 计算对比两个关键字 100 次所需的时间 15 | 16 | user=> (time 17 | (dotimes [_ 100] 18 | (= :kw :kw))) 19 | "Elapsed time: 0.23802 msecs" 20 | nil 21 | -------------------------------------------------------------------------------- /clojure.java.io/make-parents.rst: -------------------------------------------------------------------------------- 1 | make-parents 2 | =============== 3 | 4 | | **(make-parents f & more)** 5 | 6 | 创建父目录,成功返回 ``true`` 。 7 | 8 | ``f`` 和 ``more`` 可以是 ``java.lang.String`` , ``java.io.File`` , ``java.net.URL`` 或者 ``java.net.URI`` 。 9 | 10 | 11 | :: 12 | 13 | user> (use 'clojure.java.io) 14 | user> (make-parents "/tmp/a/b/c/d") ;; 创建 /tmp/a/b/c/ 15 | true 16 | user> (make-parents "/tmp/a/x/" "y" "z/") ;; 创建 /tmp/a/x/y 17 | true 18 | -------------------------------------------------------------------------------- /clojure.repl/apropos.rst: -------------------------------------------------------------------------------- 1 | apropos 2 | ============= 3 | 4 | | **(apropos str-or-pattern)** 5 | 6 | 返回当前命名空间下所有与给定正则表达式或者字符串(str-or-pattern)相匹配的定义的序列 7 | 8 | :: 9 | 10 | 11 | user=> (apropos "temp") 12 | () 13 | 14 | user=> (require 'clojure.template) 15 | nil 16 | 17 | user=> (apropos "temp") 18 | (apply-template do-template) 19 | 20 | ;; 使用正则表达式 21 | user=> (apropos #".*-temp*") 22 | (apply-template do-template) 23 | -------------------------------------------------------------------------------- /clojure.core/bigdec.rst: -------------------------------------------------------------------------------- 1 | bigdec 2 | -------- 3 | 4 | **(bigdec x)** 5 | 6 | 7 | 将 ``x`` 强制转换为 ``BigDecimal`` 。 8 | 9 | `查看源码 `_ 10 | 11 | 12 | :: 13 | 14 | user=> (bigdec 3.0) 15 | 3.0M 16 | 17 | user=> (bigdec 5) 18 | 5M 19 | 20 | user=> (bigdec -1) 21 | -1M 22 | 23 | user=> (bigdec -1.0) 24 | -1.0M 25 | 26 | 27 | -------------------------------------------------------------------------------- /clojure.java.io/resource.rst: -------------------------------------------------------------------------------- 1 | resource 2 | ================ 3 | 4 | | **(resource n)** 5 | | **(resource n loader)** 6 | 7 | 8 | 是用 ``ClassLoader`` 加载资源文件,返回 ``java.net.URL`` 对象。如果找不到资源文件,返回 ``nil``。 9 | 10 | ``n`` 是资源名字字符串。 如果要使用特定的 ``ClassLoader`` ,需要使用 ``loader`` 参数。 11 | 12 | :: 13 | 14 | user> (use 'clojure.java.io) 15 | nil 16 | user> (resource "project.clj") 17 | # 18 | -------------------------------------------------------------------------------- /clojure.repl/dir.rst: -------------------------------------------------------------------------------- 1 | dir 2 | ============= 3 | 4 | | **(dir nsname)** 5 | 6 | 分类打印出给定命名空间下的公共Var对象 7 | 8 | :: 9 | 10 | user=> (require 'clojure.string 'clojure.repl) 11 | 12 | user=> (clojure.repl/dir clojure.string) 13 | blank? 14 | capitalize 15 | escape 16 | join 17 | lower-case 18 | replace 19 | replace-first 20 | reverse 21 | split 22 | split-lines 23 | trim 24 | trim-newline 25 | triml 26 | trimr 27 | upper-case 28 | -------------------------------------------------------------------------------- /clojure.core/alter-var-root.rst: -------------------------------------------------------------------------------- 1 | alter-var-root 2 | ===================== 3 | 4 | **(alter-var-root v f & args)** 5 | 6 | 原子性地修改 var ``v`` 的值,新值由 ``v`` 的旧值和给定的 ``args`` 应用到函数 ``f`` 得出。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (def v 10) 13 | #'user/v 14 | 15 | user=> (alter-var-root (var v) + 1) ; (var v) 等同于 #'v 16 | 11 17 | 18 | user=> v 19 | 11 20 | -------------------------------------------------------------------------------- /clojure.core/count.rst: -------------------------------------------------------------------------------- 1 | count 2 | ---------- 3 | 4 | **(count coll)** 5 | 6 | 返回 ``coll`` 中元素的数量。 7 | 8 | ``(count nil)`` 返回 ``0`` 。 9 | 10 | ``coll`` 也可以是字符串、数组、Java Collection 和 Map 。 11 | 12 | :: 13 | 14 | user=> (count nil) 15 | 0 16 | 17 | user=> (count [1 2 3 4]) 18 | 4 19 | 20 | user=> (count (list 1 2 3 4)) 21 | 4 22 | 23 | user=> (count "string") 24 | 6 25 | 26 | user=> (count {:clojure "Rich" :python "Guido" :ruby :Matz}) 27 | 3 28 | 29 | 30 | -------------------------------------------------------------------------------- /clojure.core/if-not.rst: -------------------------------------------------------------------------------- 1 | if-not 2 | ------------ 3 | 4 | | **(if-not test then)** 5 | | **(if-not test then else)** 6 | 7 | 对 ``test`` 部分进行求值,如果结果为 ``false`` ,那么对 ``then`` 部分求值。 8 | 9 | 另一方面,如果 ``test`` 部分的求值结果为 ``true`` ,且 ``else`` 部分不为空,那么求值 ``else`` 部分;否则返回 ``nil`` 。 10 | 11 | :: 12 | 13 | user=> (if-not false :then-part :else-part) 14 | :then-part 15 | 16 | user=> (if-not true :then-part) 17 | nil 18 | 19 | user=> (if-not true :then-part :else-part) 20 | :else-part 21 | -------------------------------------------------------------------------------- /clojure.string/escape.rst: -------------------------------------------------------------------------------- 1 | escape 2 | ----------- 3 | 4 | **(escape s cmap)** 5 | 6 | 使用函数 ``cmap`` 对字符串 ``s`` 中的每个字符 ``ch`` 进行转义,并返回一个新字符串。 7 | 8 | 转义按照以下规则进行: 9 | 10 | * 如果 ``(cmap ch)`` 返回 ``nil`` ,那么将 ``ch`` 添加到新字符串 11 | 12 | * 如果 ``(cmap ch)`` 不为 ``nil`` ,那么将 ``(str (cmap ch))`` 添加到新字符串。 13 | 14 | :: 15 | 16 | user=> (clojure.string/escape "I want 1 < 2 as HTML, & other good things." {\< "<" \> ">" \& "&"}) 17 | "I want 1 < 2 as HTML, & other good things." 18 | 19 | -------------------------------------------------------------------------------- /clojure.core/doall.rst: -------------------------------------------------------------------------------- 1 | doall 2 | --------- 3 | 4 | | **(doall coll)** 5 | | **(doall n coll)** 6 | 7 | 8 | 对于那些带副作用的函数所生成的惰性序列来说,只有当列表的某个元素被求值时,该元素的副作用才会被显现出来。 9 | 10 | ``doall`` 使用 ``next`` 函数遍历整个序列,从而迫使惰性序列的副作用产生。 11 | 12 | 这个函数返回序列的首个元素作为结果,因此它需要在内存中保存整个序列。 13 | 14 | 自 Clojure 1.0 以来可用。 15 | 16 | :: 17 | 18 | user=> (def one-to-three (range 3)) 19 | #'user/one-to-three 20 | 21 | user=> (doall one-to-three) 22 | (0 1 2) 23 | 24 | user=> one-to-three 25 | (0 1 2) 26 | 27 | -------------------------------------------------------------------------------- /clojure.core/realized.rst: -------------------------------------------------------------------------------- 1 | realized? 2 | =========== 3 | 4 | **(realized? x)** 5 | 6 | 如果给定的 ``promise`` 、 ``delay`` 、 ``future`` 或者 ``lazy-list`` 对象已经有值了,那么返回 ``true`` 。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (def d (delay (+ 1 1))) 13 | #'user/d 14 | 15 | user=> (realized? d) 16 | false 17 | 18 | user=> @d 19 | 2 20 | 21 | user=> (realized? d) 22 | true 23 | -------------------------------------------------------------------------------- /clojure.set/intersection.rst: -------------------------------------------------------------------------------- 1 | intersection 2 | ================ 3 | 4 | | **(intersection s1)** 5 | | **(intersection s1 s2)** 6 | | **(intersection s1 s2 & sets)** 7 | 8 | 计算输入集合的交集。 9 | 10 | `查看源码 `_ 11 | 12 | :: 13 | 14 | user> (use 'clojure.set) 15 | nil 16 | 17 | user> (intersection #{1 2 3} #{3 4 5}) 18 | #{3} 19 | 20 | user> (intersection #{1 2 3} #{2 3} #{3}) 21 | #{3} 22 | -------------------------------------------------------------------------------- /clojure.set/union.rst: -------------------------------------------------------------------------------- 1 | union 2 | =========== 3 | 4 | | **(union)** 5 | | **(union s1)** 6 | | **(union s1 s2)** 7 | | **(union s1 s2 & sets)** 8 | 9 | 返回输入集合的并集。 10 | 11 | `查看源码 `_ 12 | 13 | :: 14 | 15 | user> (clojure.set/union) 16 | #{} 17 | 18 | user> (clojure.set/union #{:a} #{:b :c}) 19 | #{:a :c :b} 20 | 21 | user> (clojure.set/union #{:a :b} #{:b :c}) 22 | #{:a :c :b} 23 | -------------------------------------------------------------------------------- /clojure.core/counted.rst: -------------------------------------------------------------------------------- 1 | counted? 2 | -------------- 3 | 4 | **(counted? coll)** 5 | 6 | 如果 ``coll`` 实现了常数复杂度的 ``count`` 操作,那么返回 ``true`` 。 7 | 8 | :: 9 | 10 | ; 向量、列表、Map 和集合的 count 操作都是常数复杂度的 11 | ; 但字符串不是 12 | 13 | user=> (counted? [1 2 3]) 14 | true 15 | 16 | user=> (counted? '(1 2 3)) 17 | true 18 | 19 | user=> (counted? {:clojure "Rich"}) 20 | true 21 | 22 | user=> (counted? #{:a :b :c}) 23 | true 24 | 25 | user=> (counted? "string") 26 | false 27 | 28 | 29 | -------------------------------------------------------------------------------- /clojure.core/pcalls.rst: -------------------------------------------------------------------------------- 1 | pcalls 2 | ======= 3 | 4 | **(pcalls & fns)** 5 | 6 | 并行计算 ``fns`` 中的无参数函数,并以惰性序列的形式返回它们的值。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | ; 并行运行 3 个等待 3 秒的线程,共等待 3 秒 13 | user=> (pcalls 14 | #(Thread/sleep 3000) 15 | #(Thread/sleep 3000) 16 | #(Thread/sleep 3000)) 17 | (nil nil nil) 18 | 19 | .. include:: problem-of-pcalls-and-pvalues.rst 20 | -------------------------------------------------------------------------------- /clojure.core/remove.rst: -------------------------------------------------------------------------------- 1 | remove 2 | ---------- 3 | 4 | **(remove pred coll)** 5 | 6 | 返回一个惰性序列, 7 | 序列中包含 ``coll`` 里所有 ``(pred item)`` 测试结果为 ``false`` 的项。 8 | 9 | ``pred`` 必须是一个无副作用的函数。 10 | 11 | :: 12 | 13 | ; 删除 0 - 9 中的所有偶数 14 | 15 | user=> (remove even? (range 10)) 16 | (1 3 5 7 9) 17 | 18 | 19 | ; 删除 0 - 9 中的所有奇数 20 | 21 | user=> (remove odd? (range 10)) 22 | (0 2 4 6 8) 23 | 24 | 25 | ; 删除 0 - 9 中所有大于等于 0 的数字,结果为空 26 | 27 | user=> (remove #(>= % 0) (range 10)) 28 | () 29 | 30 | 31 | -------------------------------------------------------------------------------- /clojure.string/join.rst: -------------------------------------------------------------------------------- 1 | join 2 | ------ 3 | 4 | | **(join coll)** 5 | | **(join separator coll)** 6 | 7 | 先使用 ``(seq coll)`` 将 ``coll`` 转换为序列,然后返回一个包含序列里所有元素的字符串。 8 | 9 | 多个元素之间以一个可选的 ``separator`` 分隔开。 10 | 11 | :: 12 | 13 | user=> (def fruit ["apple" "banana" "cherry"]) 14 | #'user/fruit 15 | 16 | ; 不使用 separator 17 | 18 | user=> (clojure.string/join fruit) 19 | "applebananacherry" 20 | 21 | ; 使用 ", " 作为 separator 22 | 23 | user=> (clojure.string/join ", " fruit) 24 | "apple, banana, cherry" 25 | -------------------------------------------------------------------------------- /clojure.core/filter.rst: -------------------------------------------------------------------------------- 1 | filter 2 | -------- 3 | 4 | **(filter pred coll)** 5 | 6 | 返回一个惰性序列, 7 | 序列中包含 ``coll`` 里所有 ``(pred item)`` 测试结果为 ``true`` 的项。 8 | 9 | ``pred`` 必须是一个无副作用的函数。 10 | 11 | :: 12 | 13 | ; 过滤 0 - 9 中所有的奇数 14 | 15 | user=> (filter even? (range 10)) 16 | (0 2 4 6 8) 17 | 18 | 19 | ; 过滤 0 - 9 中所有的偶数 20 | 21 | user=> (filter odd? (range 10)) 22 | (1 3 5 7 9) 23 | 24 | 25 | ; 过滤 0 - 9 中所有小于 10086 的数,结果为空 26 | 27 | user=> (filter #(> % 10086) (range 10)) 28 | () 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /clojure.core/iterate.rst: -------------------------------------------------------------------------------- 1 | iterate 2 | -------- 3 | 4 | | **(iterate f x)** 5 | 6 | 返回一个惰性序列, 7 | 序列元素的值为 ``x`` 、 ``(f x)`` 、 ``(f (f x))`` 、 ``(f (f (f x)))`` , 8 | 诸如此类。 9 | 10 | 函数 ``f`` 必须是无副作用的。 11 | 12 | :: 13 | 14 | ; 生成一个计算所有正整数的惰性序列 15 | 16 | user=> (def z (iterate inc 1)) 17 | #'user/z 18 | 19 | 20 | ; 取出第一个和第二个正整数 21 | 22 | user=> (nth z 0) 23 | 1 24 | 25 | user=> (nth z 1) 26 | 2 27 | 28 | 29 | ; 取出前十个正整数 30 | 31 | user=> (take 10 z) 32 | (1 2 3 4 5 6 7 8 9 10) 33 | 34 | 35 | -------------------------------------------------------------------------------- /clojure.core/keep-indexed.rst: -------------------------------------------------------------------------------- 1 | keep-indexed 2 | ------------------- 3 | 4 | **(keep-indexed f coll)** 5 | 6 | 对于 ``coll`` 中的每个项 ``item`` , 7 | 以及 ``item`` 对应的索引下标 ``index`` , 8 | ``(keep-indexed f coll)`` 返回一个惰性序列, 9 | 序列中包含 ``(f index item)`` 除 ``nil`` 之外的所有计算结果。 10 | 11 | 因为带副作用的函数会返回与计算结果无关的虚假值, 12 | 因此,为了确保虚假值不会混进 ``keep-indexed`` 所生成的惰性序列中, 13 | ``f`` 必须是一个无副作用的函数。 14 | 15 | :: 16 | 17 | ; 返回 0 - 9 内所有排序位置(index)为偶数的数字 18 | 19 | user=> (keep-indexed #(if (even? %1) %2 nil) (range 10)) 20 | (0 2 4 6 8) 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /clojure.core/pvalues.rst: -------------------------------------------------------------------------------- 1 | pvalues 2 | ============ 3 | 4 | | **(pvalues & exprs)** 5 | 6 | 并行计算 ``exprs`` 中的表达式,并以惰性序列的形式返回它们的值。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (pvalues 13 | (Thread/sleep 3000) 14 | 10086 15 | (Thread/sleep 3000) 16 | "hello moto") 17 | (nil 10086 nil "hello moto") ; 返回完整的计算结果需要 3 秒时间 18 | 19 | .. include:: problem-of-pcalls-and-pvalues.rst 20 | -------------------------------------------------------------------------------- /clojure.repl/dir-fn.rst: -------------------------------------------------------------------------------- 1 | dir-fn 2 | ============= 3 | 4 | | **(dir-fn ns)** 5 | 6 | 返回一个有序序列,该序列包括给定命名空间(ns)的公共Var对象。 7 | 8 | :: 9 | 10 | user=> (require 'clojure.repl 'clojure.string) 11 | 12 | user=> (pprint (clojure.repl/dir-fn 'clojure.string)) 13 | (blank? 14 | capitalize 15 | escape 16 | join 17 | lower-case 18 | replace 19 | replace-first 20 | reverse 21 | split 22 | split-lines 23 | trim 24 | trim-newline 25 | triml 26 | trimr 27 | upper-case) 28 | nil 29 | -------------------------------------------------------------------------------- /clojure.set/subset_q.rst: -------------------------------------------------------------------------------- 1 | subset? 2 | ========= 3 | 4 | | **(subset? set1 set2)** 5 | 6 | 判断 ``set1`` 是否 ``set2`` 的子集。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user> (clojure.set/subset? #{:a :b} #{:a :b :c}) 13 | true 14 | 15 | user> (clojure.set/subset? #{:a :b} #{:a :c :d}) 16 | false 17 | 18 | user> (clojure.set/subset? #{} #{:a :c :d}) 19 | true 20 | 21 | user> (clojure.set/subset? #{:a} #{:a}) 22 | true 23 | -------------------------------------------------------------------------------- /clojure.string/split-lines.rst: -------------------------------------------------------------------------------- 1 | split-lines 2 | ---------------- 3 | 4 | **(split-lines s)** 5 | 6 | 在字符串 ``s`` 的 ``\n`` 或者 ``\r\n`` 处分割开。 7 | 8 | :: 9 | 10 | user=> (clojure.string/split-lines "hello\nmoto\r\nagain\r\n") 11 | ["hello" "moto" "again"] 12 | 13 | user=> (clojure.string/split-lines "no-new-lines") 14 | ["no-new-lines"] 15 | 16 | user=> (clojure.string/split-lines "") 17 | [""] 18 | 19 | user=> (clojure.string/split-lines nil) 20 | ;NullPointerException java.util.regex.Matcher.getTextLength (Matcher.java:1234) 21 | -------------------------------------------------------------------------------- /clojure.set/superset_q.rst: -------------------------------------------------------------------------------- 1 | superset? 2 | =========== 3 | 4 | | **(superset? set1 set2)** 5 | 6 | 判断 ``set1`` 是否 ``set2`` 的超集。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user> (clojure.set/superset? #{:a :b :c} #{:a :b}) 13 | true 14 | 15 | user> (clojure.set/superset? #{:a :c :d} #{:a :b}) 16 | false 17 | 18 | user> (clojure.set/superset? #{:a :b} #{:a :b}) 19 | true 20 | 21 | user> (clojure.set/superset? #{:a :b} #{}) 22 | true 23 | -------------------------------------------------------------------------------- /clojure.core/comment.rst: -------------------------------------------------------------------------------- 1 | comment 2 | ========== 3 | 4 | **(comment & body)** 5 | 6 | 忽略 ``body`` ,返回 ``nil`` 。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user=> (comment hello-clojure) 13 | nil 14 | 15 | user=> (comment "clojure!") 16 | nil 17 | 18 | user=> (defn msg [] 19 | (comment "nothing but a greeting message here") 20 | (println "hello")) 21 | #'user/msg 22 | 23 | user=> (msg) 24 | hello 25 | nil 26 | -------------------------------------------------------------------------------- /clojure.core/keep.rst: -------------------------------------------------------------------------------- 1 | keep 2 | --------- 3 | 4 | **(keep f coll)** 5 | 6 | 对于 ``coll`` 中的每个项 ``item`` , 7 | ``(keep f coll)`` 返回一个惰性序列, 8 | 序列包含 ``(f item)`` 除 ``nil`` 之外的所有计算结果。 9 | 10 | 因为带副作用的函数会返回与计算结果无关的虚假值, 11 | 因此,为了确保虚假值不会混进 ``keep`` 所生成的惰性序列中, 12 | ``f`` 必须是一个无副作用的函数。 13 | 14 | :: 15 | 16 | user=> (keep inc [1 2 3]) 17 | (2 3 4) 18 | 19 | ; 将空的 collection 传给 seq 函数会返回 nil 20 | ; 可以根据这个性质来测试 keep 21 | ; 看它是否真的会省略等于 nil 的值 22 | 23 | user=> (seq []) 24 | nil 25 | 26 | user=> (keep seq (list [1 2 3] [] [4 5 6])) 27 | ((1 2 3) (4 5 6)) 28 | -------------------------------------------------------------------------------- /clojure.set/rename.rst: -------------------------------------------------------------------------------- 1 | rename 2 | =========== 3 | 4 | | **(rename xrel kmap)** 5 | 6 | 把 ``xrel`` 中的元素的key改名,新旧名字的映射由 ``kmap`` 提供。 7 | 8 | `查看源码 `_ 9 | 10 | :: 11 | 12 | user> (use 'clojure.set) 13 | nil 14 | 15 | user> (def students 16 | #{{:id 1 :name "Li Lei"} 17 | {:id 2 :name "Han Meimei"}}) 18 | #'user/students 19 | 20 | user> (rename students {:id :student-id}) 21 | #{{:name "Han Meimei", :student-id 2} {:name "Li Lei", :student-id 1}} 22 | -------------------------------------------------------------------------------- /clojure.java.io/index.rst: -------------------------------------------------------------------------------- 1 | clojure.java.io 2 | ======================= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | Coercions 8 | 9 | copy 10 | 11 | IOFactory 12 | 13 | input-stream 14 | 15 | as-file 16 | 17 | as-relative-path 18 | 19 | as-url 20 | 21 | default-streams-impl 22 | 23 | delete-file 24 | 25 | file 26 | 27 | make-input-stream 28 | 29 | make-output-stream 30 | 31 | make-parents 32 | 33 | make-reader 34 | 35 | make-writer 36 | 37 | output-stream 38 | 39 | reader 40 | 41 | resource 42 | 43 | writer 44 | -------------------------------------------------------------------------------- /clojure.core/max-key.rst: -------------------------------------------------------------------------------- 1 | max-key 2 | ========== 3 | 4 | | **(max-key f item1)** 5 | | **(max-key f item1 item2)** 6 | | **(max-key f item1 item2 & items)** 7 | 8 | 将函数 ``f`` 应用到所有给定元素上,其中 ``(f item)`` 值最大的那个 ``item`` 被返回。 9 | 10 | ``(f item)`` 的结果必须是数字值。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user=> (max-key count "abc" 17 | "abcd" 18 | "a" 19 | "abcdefg" 20 | "aa") 21 | "abcdefg" 22 | 23 | -------------------------------------------------------------------------------- /clojure.core/min-key.rst: -------------------------------------------------------------------------------- 1 | min-key 2 | ========= 3 | 4 | | **(min-key f item1)** 5 | | **(min-key f item1 item2)** 6 | | **(min-key f item1 item2 & items)** 7 | 8 | 将函数 ``f`` 应用到所有给定元素上,其中 ``(f item)`` 值最小的那个 ``item`` 被返回。 9 | 10 | ``(f item)`` 的结果必须是数字值。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user=> (min-key count "aaaaaaa" 17 | "bbbbbb" 18 | "ccccccc" 19 | "aa" 20 | "dddddddd") 21 | "aa" 22 | 23 | -------------------------------------------------------------------------------- /clojure.java.javadoc/javadoc.rst: -------------------------------------------------------------------------------- 1 | javadoc 2 | ============ 3 | 4 | **(javadoc class-or-object)** 5 | 6 | 使用阅览器打开 ``class-or-object`` 参数的相关 javadoc 文档。 7 | 8 | 优先打开本地文档( ``*local-javadocs*`` ), 9 | 其次才是远程文档( ``*remote-javadoc*`` )。 10 | 11 | `查看源码 `_ 12 | 13 | :: 14 | 15 | user=> (use 'clojure.java.javadoc) 16 | nil 17 | 18 | user=> (javadoc String) 19 | "http://java.sun.com/javase/6/docs/api/java/lang/String.html" 20 | 21 | user=> (javadoc (java.util.Date.)) 22 | "http://java.sun.com/javase/6/docs/api/java/util/Date.html" 23 | -------------------------------------------------------------------------------- /clojure.string/trim-newline.rst: -------------------------------------------------------------------------------- 1 | trim-newline 2 | ---------------- 3 | 4 | **(trim-newline s)** 5 | 6 | 从字符串的末尾移除转行符 ``\n`` 和返回符 ``\r`` 。 7 | 8 | 类似于 Perl 的 ``chomp`` 函数。 9 | 10 | :: 11 | 12 | user=> (clojure.string/trim-newline "test\n") 13 | "test" 14 | 15 | user=> (clojure.string/trim-newline "test\r") 16 | "test" 17 | 18 | user=> (clojure.string/trim-newline "test\n\r") 19 | "test" 20 | 21 | user=> (clojure.string/trim-newline "test\r\n") 22 | "test" 23 | 24 | ; 只移除末尾的换行符 25 | 26 | user=> (clojure.string/trim-newline "leading newline\n trailing newline\n") 27 | "leading newline\n trailing newline" 28 | -------------------------------------------------------------------------------- /clojure.set/select.rst: -------------------------------------------------------------------------------- 1 | select 2 | ============ 3 | 4 | | **(select pred xset)** 5 | 6 | 返回 ``xset`` 中所有使 ``pred`` 为真的元素。 7 | 8 | ``select`` 和 ``clojure.core/filter`` 类似,只是 ``select`` 的输入和输出都是 ``set`` 。 9 | 10 | `查看源码 `_ 11 | 12 | :: 13 | 14 | user=> (use 'clojure.set) 15 | nil 16 | 17 | user=> (select even? #{1 2 3 4 5}) 18 | #{2 4} 19 | 20 | user=> (select even? [1 2 3 4 5]) ;; 只能是set 21 | ClassCastException clojure.lang.PersistentVector cannot be cast to clojure.lang.IPersistentSet clojure.core/disj (core.clj:1420) 22 | -------------------------------------------------------------------------------- /clojure.java.io/reader.rst: -------------------------------------------------------------------------------- 1 | reader 2 | ============ 3 | 4 | | **(reader x & opts)** 5 | 6 | 根据 ``x`` 创建一个 ``java.io.BufferedReader`` 。``x`` 可以是 ``java.io.InputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` , ``byte`` 数组或者 ``char`` 数组 。 7 | 8 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 9 | 10 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 11 | 12 | 13 | :: 14 | 15 | user> (use 'clojure.java.io) 16 | nil 17 | user> (reader "http://baidu.com" :encoding "GB2312") 18 | ;;# 19 | -------------------------------------------------------------------------------- /clojure.core/map-indexed.rst: -------------------------------------------------------------------------------- 1 | map-indexed 2 | ============== 3 | 4 | | **(map-indexed f coll)** 5 | 6 | 返回一个惰性序列, 7 | 序列里的第一个元素是将 ``0`` 和 ``coll`` 的第一个元素应用到 ``f`` 所得出的值, 8 | 序列里的第二个元素是将 ``1`` 和 ``coll`` 的第二个元素应用到 ``f`` 所得出的值。。。 9 | 以此类推,直到 ``coll`` 被处理完为止。 10 | 11 | 函数 ``f`` 应该接受两个参数:一个索引值,一个是 ``coll`` 的元素值。 12 | 13 | `查看源码 `_ 14 | 15 | :: 16 | 17 | user=> (map-indexed (fn [idx item] [idx item]) "foobar") 18 | ([0 \f] [1 \o] [2 \o] [3 \b] [4 \a] [5 \r]) 19 | 20 | user=> (map-indexed vector "foobar") ; 另一种更简单的解法 21 | ([0 \f] [1 \o] [2 \o] [3 \b] [4 \a] [5 \r]) 22 | 23 | -------------------------------------------------------------------------------- /clojure.java.io/make-reader.rst: -------------------------------------------------------------------------------- 1 | make-reader 2 | ================= 3 | 4 | | **(make-reader x opts)** 5 | 6 | 根据 ``x`` 创建一个 ``java.io.BufferedReader`` 。``x`` 可以是 ``java.io.InputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` , ``byte`` 数组或者 ``char`` 数组 。 7 | 8 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 9 | 10 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 11 | 12 | 13 | :: 14 | 15 | user> (use 'clojure.java.io) 16 | nil 17 | user> (make-reader "http://baidu.com" {}) 18 | ;;# 19 | -------------------------------------------------------------------------------- /clojure.set/map-invert.rst: -------------------------------------------------------------------------------- 1 | map-invert 2 | ============ 3 | 4 | 5 | | **(map-invert m)** 6 | 7 | 反转一个 ``map`` ,将它原本的 ``value`` 映射为新 ``map`` 的 ``key`` ,原本的 ``key`` 映射为新 ``map`` 的 ``value`` 。 8 | 9 | .. note:: 当多个 ``key`` 有同一个 ``value`` 时,新 ``map`` 只保留其中的一个作为 ``key`` 。 10 | 11 | .. p.s. 为毛这个函数在 ``clojure.set`` 里头... 12 | 13 | `查看源码 `_ 14 | 15 | :: 16 | 17 | user> (use 'clojure.set) 18 | nil 19 | 20 | user> (map-invert {:a 1 :b 2}) 21 | {2 :b, 1 :a} 22 | 23 | user> (map-invert {:a 1 :b 2 :c 2}) ;; 两个 2 冲突,丢掉了 :c 24 | {2 :b, 1 :a} 25 | -------------------------------------------------------------------------------- /clojure.core/get.rst: -------------------------------------------------------------------------------- 1 | get 2 | ==== 3 | 4 | | **(get map key)** 5 | | **(get map key not-found)** 6 | 7 | 返回 ``map`` 中 ``key`` 所映射的值。 8 | 9 | 如果该 ``key`` 不存在,且给定了 ``not-found`` ,那么返回 ``not-found`` ,否则,返回 ``nil`` 。 10 | 11 | `查看源码 `_ 12 | 13 | :: 14 | 15 | user=> (def clojure {:author "Rich Hickey"}) 16 | #'user/clojure 17 | 18 | user=> (get clojure :author) 19 | "Rich Hickey" 20 | 21 | user=> (get clojure :version) ; 无 not-found 参数 22 | nil 23 | 24 | user=> (get clojure :version 1.4) ; 有 not-found 参数 25 | 1.4 26 | 27 | -------------------------------------------------------------------------------- /clojure.java.io/as-relative-path.rst: -------------------------------------------------------------------------------- 1 | as-relative-file 2 | ==================== 3 | 4 | | **(as-relative-path x)** 5 | 6 | 接受一个 ``x`` 参数,据此返回相对路径字符串。 ``x`` 的类型可以是 ``java.lang.String`` , ``java.io.File`` , ``java.net.URL`` 和 ``java.net.URI`` ,跟 ``as-file`` 一样。 7 | 8 | 如果 ``x`` 不是用相对路径表示的,则抛出 ``IllegalArgumentException`` 。 9 | 10 | :: 11 | 12 | user> (as-relative-path "./tmp") 13 | "./tmp" 14 | user> (as-relative-path "tmp") 15 | "tmp" 16 | user> (as-relative-path "/tmp") 17 | ;;IllegalArgumentException /tmp is not a relative path clojure.java.io/as-relative-path (io.clj:404) 18 | user> (as-relative-path (java.io.File. "tmp-file")) 19 | "tmp-file" 20 | -------------------------------------------------------------------------------- /clojure.core/defonce.rst: -------------------------------------------------------------------------------- 1 | defonce 2 | ----------- 3 | 4 | **(defonce name expr)** 5 | 6 | 将 ``name`` 的 root value 设置为 ``expr`` 的值,当且仅当 ``name`` 还没有设置 root value 。 7 | 8 | 如果 ``name`` 已经有 root value ,那么 ``expr`` 不会被求值。 9 | 10 | 11 | :: 12 | 13 | user=> number ; 没有 root value 14 | ;CompilerException java.lang.RuntimeException: Unable to resolve symbol: number in this context, compiling:(NO_SOURCE_PATH:0) 15 | 16 | user=> (defonce number 10086) ; 设置 root value 17 | #'user/number 18 | 19 | user=> number 20 | 10086 21 | 22 | user=> (defonce number 123123) ; 已有 root value ,设置失败 23 | nil 24 | 25 | user=> number 26 | 10086 27 | -------------------------------------------------------------------------------- /clojure.core/with-open.rst: -------------------------------------------------------------------------------- 1 | with-open 2 | --------------- 3 | 4 | **(with-open bindings & body)** 5 | 6 | 在绑定了名字 ``name`` 与初始值 ``init`` 的 ``try`` 表达式里面对 ``body`` 进行求值 7 | 并按照绑定时间从晚到早的顺序 8 | 在 ``finally`` 语句里面对每个 ``name`` 执行 ``(.close name)`` 调用 9 | 10 | 11 | :: 12 | 13 | (ns io 14 | (:require [clojure.java.io :as io])) 15 | 16 | (defn readLineByLine [file-name] 17 | (with-open [reader (io/reader file-name)] 18 | (doseq [line (line-seq reader)] 19 | (println line)))) 20 | 21 | (defn copyLineByLine [source target] 22 | (with-open [reader (io/reader source) 23 | writer (io/writer target)] 24 | (io/copy reader writer))) 25 | -------------------------------------------------------------------------------- /clojure.core/if-let.rst: -------------------------------------------------------------------------------- 1 | if-let 2 | -------- 3 | 4 | | **(if-let bindings then)** 5 | | **(if-let bindings then else & oldform)** 6 | 7 | | **bindings => binding-form test** 8 | 9 | 如果 ``test`` 为真,那么结合 ``binding-form`` 绑定,对 ``then`` 部分进行求值。 10 | 11 | 如果 ``test`` 为假,那么对 ``else`` 部分进行求值。 12 | 13 | :: 14 | 15 | user=> (defn sum-all-even-number [all-number] 16 | (if-let [all-even-number (filter even? all-number)] 17 | (reduce + all-even-number) 18 | 0)) 19 | #'user/sum-all-even-number 20 | 21 | user=> (sum-all-even-number [1 2 3 4 5 6 7 8 9]) 22 | 20 ; 2 + 4 + 6 + 8 23 | 24 | user=> (sum-all-even-number [1 3 5 7 9]) 25 | 0 26 | -------------------------------------------------------------------------------- /clojure.core/some.rst: -------------------------------------------------------------------------------- 1 | some 2 | ------ 3 | 4 | **(some pred coll)** 5 | 6 | 如果 ``coll`` 中有一个元素 ``x`` 能满足 ``(pred x)`` ,则返回``(pred x)``的值 7 | 8 | 如果 ``coll`` 中没有任何元素 ``x`` 能满足 ``(pred x)`` , 9 | 返回 ``nil`` 。 10 | 11 | 将一个集合用作 ``pred`` 是 ``some`` 的一个惯用法: 12 | 比如说, 13 | ``(some #{:fred} coll)`` 在 ``:fred`` 存在于 ``coll`` 时返回 ``:fred`` , 14 | 如果不存在,就返回 ``nil`` 。 15 | 16 | :: 17 | 18 | user=> (some #{:fred} [:fred :peter :jack]) 19 | :fred 20 | 21 | user=> (some #{:mary} [:fred :peter :jack]) 22 | nil 23 | 24 | user=> (some #(>= % 10) [1 3 5 7 9]) ; 查看是否有 >= 10 的值存在 25 | nil 26 | 27 | user=> (some #(>= % 5) [1 3 5 7 9]) ; 查看是否有 >= 5 的值存在 28 | true 29 | 30 | 31 | -------------------------------------------------------------------------------- /clojure.repl/find-doc.rst: -------------------------------------------------------------------------------- 1 | find-doc 2 | ============= 3 | 4 | | **(find-doc re-string-or-pattern)** 5 | 6 | 如果某个Var对象的名字或者文档能与给定字符串或者正则表达式相匹配,那么打印该Var对象的文档信息。 7 | 8 | :: 9 | 10 | user=> (find-doc "data structure") 11 | 12 | ------------------------- 13 | clojure.core/eval 14 | ([form]) 15 | Evaluates the form data structure (not text!) and returns the result. 16 | ------------------------- 17 | clojure.core/ifn? 18 | ([x]) 19 | Returns true if x implements IFn. Note that many data structures 20 | (e.g. sets and maps) implement IFn 21 | user=> (require 'clojure.string 'clojure.repl) 22 | ------------------------- 23 | ........ 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /clojure.pprint/index.rst: -------------------------------------------------------------------------------- 1 | clojure.pprint 2 | ================ 3 | 4 | | **(A Pretty Printer for Clojure)** 5 | 6 | clojure.pprint 实现了一个灵活的工具,用于把clojure的数据结构输出成优雅易懂的格式。pretty printer最基本的使用方式,就是把代码中的 println 替换成 pprint。高级用户可以通过 the building blocks 来定制自己的输出格式。 7 | 8 | pprint 对基础的数据提供了简单的格式,对 clojure source code 提供了专有的格式。其他更高级的格式,包括完全不像 clojure 惯用的数据格式的 XML ,JSON ,都可以通过自定义补丁来输出出来。 9 | 10 | 这个模块不仅包括 pprint, 也包括给 Common lisp 提供支持的 cl-format。因为 pprint 和 cl-format 需要共同作用,所以 pprint 支持非常简洁的自定义补丁。除此之外, pprint 也提供了 format function 作为 clojure 现有的标准 format function的一个替代。 11 | 12 | 欢迎查看 pprint 和 cl-format 的文档来获取更多的信息。 13 | 14 | Added in Clojure version 1.2 15 | 16 | .. toctree:: 17 | :maxdepth: 2 18 | 19 | cl-format 20 | pp 21 | -------------------------------------------------------------------------------- /clojure.core/cond.rst: -------------------------------------------------------------------------------- 1 | cond 2 | --------- 3 | 4 | **(cond & clauses)** 5 | 6 | 接受一系列 ``test``/``expression`` 对, 7 | 它每次对一个 ``test`` 进行求值, 8 | 如果某个 ``test`` 返回 ``true`` , 9 | 那么 ``cond`` 求值并返回与这个 ``test`` 相对应的 ``expression`` , 10 | 并且不再对其他 ``test`` 进行求值。 11 | 12 | ``(cond)`` 返回 ``nil`` 。 13 | 14 | :: 15 | 16 | user=> (defn type-of-number [n] 17 | (cond (> n 0) "positive number" 18 | (< n 0) "negative number" 19 | :else "zero")) 20 | #'user/type-of-number 21 | 22 | user=> (type-of-number 10) 23 | "positive number" 24 | 25 | user=> (type-of-number -5) 26 | "negative number" 27 | 28 | user=> (type-of-number 0) 29 | "zero" 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /clojure.core/contains.rst: -------------------------------------------------------------------------------- 1 | contains? 2 | --------------- 3 | 4 | **(contains? coll key)** 5 | 6 | 如果 ``key`` 存在于给定 ``coll`` 中, 7 | 那么返回 ``true`` ,否则返回 ``false`` 。 8 | 9 | 对于那些使用数值索引(index)的 collection 、比如向量和 Java 数组来说, 10 | ``contains?`` 用于测试给定的数值 ``key`` 是否在索引的范围(range)之内。 11 | 12 | ``contains?`` 不是线性复杂度的操作, 13 | 它可以在常数或对数复杂度内完成。 14 | 15 | 如果要检查一个 ``coll`` 是否符合某个条件,可以使用 `some` 函数。 16 | 17 | :: 18 | 19 | user=> (contains? {:clojure "Rich"} :python) ; 测试 Map 20 | false 21 | 22 | user=> (contains? {:clojure "Rich"} :clojure) 23 | true 24 | 25 | user=> (contains? [1 3 5 7 9] 3) ; 测试向量 26 | true 27 | 28 | user=> (contains? [1 3 5 7 9] 10086) 29 | false 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /clojure.core/reductions.rst: -------------------------------------------------------------------------------- 1 | reductions 2 | ============ 3 | 4 | | **(reductions f coll)** 5 | | **(reductions f init coll)** 6 | 7 | 返回一个惰性序列, 8 | 序列里包含计算 ``(reduce f coll)`` 所产生的所有中间结果。 9 | 10 | 如果给定了 ``init`` ,那么将它用作所有中间结果的初始值。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user=> (reduce + (range 1 10)) 17 | 45 18 | 19 | user=> (reductions + (range 1 10)) 20 | (1 3 6 10 15 21 28 36 45) 21 | 22 | user=> (reductions + 0 (range 1 10)) ; 注意 init 不止添加到序列头那么简单 23 | (0 1 3 6 10 15 21 28 36 45) 24 | 25 | user=> (reductions + 10 (range 1 10)) ; 它还作为每个中间值的初始化值 26 | (10 11 13 16 20 25 31 38 46 55) 27 | -------------------------------------------------------------------------------- /clojure.core/seq.rst: -------------------------------------------------------------------------------- 1 | seq 2 | ------ 3 | 4 | **(seq coll)** 5 | 6 | 根据给定的 ``coll`` ,返回一个相应的序列。 7 | 8 | 当 ``coll`` 为空时,返回 ``nil`` 。 9 | 10 | ``(sql nil)`` 也返回 ``nil`` 。 11 | 12 | ``seq`` 函数也可以作用于字符串、 13 | (带有引用类型的)原生 Java 数组, 14 | 以及任何实现了 ``iterable`` 接口的对象。 15 | 16 | :: 17 | 18 | ; 处理空向量和 nil 19 | 20 | user=> (seq []) 21 | nil 22 | 23 | user=> (seq nil) 24 | nil 25 | 26 | ; 处理非空向量、列表、 Map 和字符串 27 | 28 | user=> (seq [1 2 3]) 29 | (1 2 3) 30 | 31 | user=> (seq (list 1 2 3)) 32 | (1 2 3) 33 | 34 | user=> (seq {:language "clojure" :creator "Rich Hickey"}) 35 | ([:creator "Rich Hickey"] [:language "clojure"]) 36 | 37 | user=> (seq "hello world") 38 | (\h \e \l \l \o \space \w \o \r \l \d) 39 | -------------------------------------------------------------------------------- /clojure.java.io/writer.rst: -------------------------------------------------------------------------------- 1 | writer 2 | ========= 3 | 4 | | **(writer x & opts)** 5 | 6 | 跟据 ``x`` 构造 ``java.io.BufferedWriter`` 。 7 | 8 | ``x`` 可以是 ``java.io.BufferOutputStream`` , ``java.io.OutputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` 。 9 | 10 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 11 | 12 | 当 ``x`` 是 ``java.net.URL`` 和 ``java.net.URI`` 时,协议必须是 ``file`` 。 13 | 14 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 15 | 16 | 17 | :: 18 | 19 | user> (use 'clojure.java.io) 20 | nil 21 | user> (writer (java.net.URL. "file:///tmp/x") :append true) 22 | ;;# 23 | -------------------------------------------------------------------------------- /clojure.java.io/make-writer.rst: -------------------------------------------------------------------------------- 1 | make-writer 2 | =============== 3 | 4 | | **(make-writer x opts)** 5 | 6 | 跟据 ``x`` 构造 ``java.io.BufferedWriter`` 。 7 | 8 | ``x`` 可以是 ``java.io.BufferOutputStream`` , ``java.io.OutputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` 。 9 | 10 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 11 | 12 | 当 ``x`` 是 ``java.net.URL`` 和 ``java.net.URI`` 时,协议必须是 ``file`` 。 13 | 14 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 15 | 16 | 17 | :: 18 | 19 | user> (use 'clojure.java.io) 20 | nil 21 | user> (make-writer (java.io.File. "/tmp/xxx") {}) 22 | ;;# 23 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/ie6.css: -------------------------------------------------------------------------------- 1 | * html img, 2 | * html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none", 3 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')", 4 | this.src = "_static/transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''), 5 | this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "',sizingMethod='crop')", 6 | this.runtimeStyle.backgroundImage = "none")),this.pngSet=true) 7 | );} 8 | -------------------------------------------------------------------------------- /clojure.core/dorun.rst: -------------------------------------------------------------------------------- 1 | dorun 2 | --------- 3 | 4 | | **(dorun coll)** 5 | | **(dorun n coll)** 6 | 7 | 对于那些带副作用的函数所生成的惰性序列来说,只有当列表的某个元素被求值时,该元素的副作用才会被显现出来。 8 | 9 | ``dorun`` 使用 ``next`` 函数遍历整个序列,从而迫使惰性列表的副作用产生。 10 | 11 | 这个函数返回 ``nil`` ,而不是序列的首个元素。 12 | 13 | 自 Clojure 1.0 版本以来可用。 14 | 15 | :: 16 | 17 | user=> (def infinity-hi (repeatedly #(println "hi"))) 18 | #'user/infinity-hi 19 | 20 | user=> (dorun 5 infinity-hi) 21 | hi 22 | hi 23 | hi 24 | hi 25 | hi 26 | hi 27 | nil 28 | 29 | user=> (def one-to-ten (map println (range 10))) 30 | #'user/one-to-ten 31 | 32 | user=> (dorun one-to-ten) 33 | 0 34 | 1 35 | 2 36 | 3 37 | 4 38 | 5 39 | 6 40 | 7 41 | 8 42 | 9 43 | nil 44 | -------------------------------------------------------------------------------- /clojure.set/rename-keys.rst: -------------------------------------------------------------------------------- 1 | rename-keys 2 | ============ 3 | 4 | | **(rename-keys map kmap)** 5 | 6 | 把 ``map`` 中的 key 按照 ``kmap`` 提供的映射改名。 7 | 8 | 可以使用 ``array-map`` 类型的 ``kmap`` 来指定替换执行的顺序。 9 | 10 | 注意,替换可能造成 key 冲突,导致原来的 key-value 对被覆盖。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user> (rename-keys {:id 1 :name "Li Lei"} {:id :new-id :name :new-name}) 17 | {:new-id 1, :new-name "Li Lei"} 18 | 19 | ; 改名造成 key 冲突,旧的 {:b 2} 被覆盖 20 | 21 | user> (rename-keys {:a 1 :b 2} {:a :b}) 22 | {:b 1} 23 | 24 | ; 通过 array-map 指定替换执行的顺序 25 | 26 | user> (rename-keys {:a 1 :b 2 :c 3} (array-map :a :tmp :b :a :tmp :b)) 27 | {:b 1, :a 2, :c 3} 28 | -------------------------------------------------------------------------------- /clojure.core/repeat.rst: -------------------------------------------------------------------------------- 1 | repeat 2 | ---------- 3 | 4 | | **(repeat x)** 5 | | **(repeat n x)** 6 | 7 | 返回一个包含 ``n`` 个 ``x`` 的惰性序列。 8 | 9 | 如果不指定 ``n`` ,那么值 ``x`` 可以被包含无限次。 10 | 11 | :: 12 | 13 | ; 定义一个包含 10 个 "hi" 的惰性序列 14 | 15 | user=> (def ten-hi (repeat 10 "hi")) 16 | #'user/ten-hi 17 | 18 | user=> ten-hi 19 | ("hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi") 20 | 21 | 22 | ; 定义一个包含无限个 "hi" 的惰性序列 23 | 24 | user=> (def infinite-hi (repeat "hi")) 25 | #'user/infinite-hi 26 | 27 | user=> (take 10 infinite-hi) 28 | ("hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi") 29 | 30 | user=> (take 20 infinite-hi) 31 | ("hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi" "hi") 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /clojure.core/concat.rst: -------------------------------------------------------------------------------- 1 | concat 2 | --------- 3 | 4 | | **(concat)** 5 | | **(concat x)** 6 | | **(concat x y)** 7 | | **(concat x y & zs)** 8 | 9 | 返回一个惰性序列,序列里包含所有传入 collection 的全部元素。 10 | 11 | :: 12 | 13 | ; 另个、一个或多个 collection 组合 14 | 15 | user=> (concat) 16 | () 17 | 18 | user=> (concat [1]) 19 | (1) 20 | 21 | user=> (concat [1] [2]) 22 | (1 2) 23 | 24 | user=> (concat [1] [2] [3]) 25 | (1 2 3) 26 | 27 | user=> (concat [1] [2] [3] [4 5 6]) 28 | (1 2 3 4 5 6) 29 | 30 | 31 | ; 传入 concat 的参数必须都是 collection 32 | ; 组合元素和 collection 是 cons 和 conj 的任务 33 | 34 | ; user=> (concat 1 [2 3]) 35 | ; IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:487) 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /clojure.core/tree-seq.rst: -------------------------------------------------------------------------------- 1 | tree-seq 2 | ---------- 3 | 4 | **(tree-seq branch? children root)** 5 | 6 | 返回一个惰性序列, 7 | 序列里包含通过深度优先遍历得出的一棵树中的所有节点。 8 | 9 | ``branch?`` 函数接受一个参数, 10 | 通过向它传入一个节点,可以判断该节点是否拥有子节点。 11 | 12 | ``children`` 函数接受一个参数, 13 | 通过向它传入一个节点,可以得到一个包含该节点的所有子节点的序列。 14 | 15 | ``children`` 函数只会在那些 16 | ``branch?`` 函数返回 ``true`` 的节点被调用。 17 | 18 | ``root`` 是树的根节点。 19 | 20 | :: 21 | 22 | ; 函数 file-seq 用于列出一个文件夹的整个目录树 23 | ; 它是展示 tree-seq 用法的一个极好的例子 24 | 25 | (defn file-seq 26 | [dir] 27 | (tree-seq 28 | (fn [^java.io.File f] (. f (isDirectory))) ; 检查文件 f 是不是一个文件夹 29 | (fn [^java.io.File d] (seq (. d (listFiles)))) ; 如果是的话,就用 listFiles 方法遍历它 30 | dir)) ; 树的根节点是传入的文件夹 31 | 32 | 33 | -------------------------------------------------------------------------------- /clojure.java.io/as-file.rst: -------------------------------------------------------------------------------- 1 | as-file 2 | =============== 3 | 4 | | **(as-file x)** 5 | 6 | 接受一个 ``x`` 参数,返回一个 ``java.io.File`` 对象。 ``x`` 的类型可以是 ``java.lang.String`` , ``java.io.File`` , ``java.net.URL`` 和 ``java.net.URI`` 。 7 | 8 | 当 ``x`` 的类型是 ``java.net.URL`` 和 ``java.net.URI`` 时,协议必须是 ``file`` 。 9 | 10 | 当 ``x`` 是 ``nil`` 时,返回 ``nil`` 。 11 | 12 | 13 | 14 | :: 15 | 16 | user> (use 'clojure.java.io) 17 | nil 18 | user> (.exists (as-file "/tmp")) 19 | true 20 | user> (.exists (as-file (java.io.File. "/tmp"))) 21 | true 22 | user> (.exists (as-file (java.net.URL. "file:///tmp"))) 23 | true 24 | user> (.exists (as-file (java.net.URL. "http://www.google.com"))) 25 | ;;IllegalArgumentException Not a file: http://www.google.com clojure.java.io/fn--8210 (io.clj:67) 26 | -------------------------------------------------------------------------------- /clojure.repl/doc.rst: -------------------------------------------------------------------------------- 1 | doc 2 | ============= 3 | 4 | | **(doc name)** 5 | 6 | 打印出某个Var对象或者special form的文档信息 7 | 8 | :: 9 | 10 | => (doc map) 11 | ;; prints in console: 12 | ------------------------- 13 | clojure.core/map 14 | ([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls]) 15 | Returns a lazy sequence consisting of the result of applying f to the 16 | set of first items of each coll, followed by applying f to the set 17 | of second items in each coll, until any one of the colls is 18 | exhausted. Any remaining items in other colls are ignored. Function 19 | f should accept number-of-colls arguments. 20 | 21 | => (doc clojure.core) 22 | ------------------------- 23 | clojure.core 24 | Fundamental library of the Clojure language 25 | -------------------------------------------------------------------------------- /clojure.set/project.rst: -------------------------------------------------------------------------------- 1 | project 2 | =========== 3 | 4 | | **(project xrel ks)** 5 | 6 | 对于 ``xrel`` 中的每个元素, ``project`` 的结果集合只包含那些 ``key`` 在 ``ks`` 里出现过的元素为成员。 7 | 8 | 换一种说法来讲就是:将 ``xrel`` 的成员投影到 ``ks`` 指定的维度上。 9 | 10 | `查看源码 `_ 11 | 12 | :: 13 | 14 | user> (use 'clojure.set) 15 | nil 16 | 17 | user> (def points ;; 定义三个三维空间的点 18 | #{{:x 1 :y 0 :z 1} 19 | {:x 0 :y 1 :z 1} 20 | {:x 1 :y 1 :z 0}}) 21 | #'user/points 22 | 23 | user> (project points [:x]) ;; 投影到 x 轴上 24 | #{{:x 0} {:x 1}} ;; 返回值是一个集合,所以计算结果中的两个 {:x 1} 只有一个被保留 25 | 26 | user> (project points [:x :y]) 27 | #{{:y 1, :x 0} {:y 1, :x 1} {:y 0, :x 1}} ;; 投影到 x-y 平面上 28 | -------------------------------------------------------------------------------- /clojure.java.io/delete-file.rst: -------------------------------------------------------------------------------- 1 | delete-file 2 | ============== 3 | 4 | | **(delete-file f & [silently])** 5 | 6 | 删除文件 ``f`` 。如果有第二个参数,且为真值,则当文件不存在的时候,不抛出异常。 7 | 8 | :: 9 | 10 | user> (use 'clojure.java.io) 11 | nil 12 | user> (spit "/tmp/x" "123") ;; 创建一个文件,写入内容 13 | nil 14 | user> (slurp "/tmp/x") ;; 验证一下,已经存在 15 | "123" 16 | user> (delete-file "/tmp/x") ;; 删掉它 17 | true 18 | user> (slurp "/tmp/x") ;; 没有了 19 | ;;FileNotFoundException /tmp/x (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2) 20 | user> (delete-file "/tmp/x") ;; 抛异常 21 | ;;IOException Couldn't delete /tmp/x clojure.java.io/delete-file (io.clj:425) 22 | user> (delete-file "/tmp/x" true) ;; 安静删除 23 | true 24 | -------------------------------------------------------------------------------- /clojure.java.io/as-url.rst: -------------------------------------------------------------------------------- 1 | as-url 2 | =============== 3 | 4 | | **(as-url x)** 5 | 6 | 接受一个 ``x`` 参数,返回一个 ``java.net.URL`` 对象。 ``x`` 的类型可以是 ``java.lang.String`` , ``java.io.File`` , ``java.net.URL`` 和 ``java.net.URI`` 。 7 | 8 | 当 ``x`` 的类型是 ``java.lang.String`` 时, ``x`` 必须是一个合法的URL。 9 | 10 | 当 ``x`` 是 ``nil`` 时,返回 ``nil`` 。 11 | 12 | 如果提供了 ``km`` 参数,则按照 ``km`` 所列出的key进行join。 13 | 14 | 15 | :: 16 | 17 | user> (use 'clojure.java.io) 18 | nil 19 | user> (as-url "http://baidu.com") 20 | # 21 | user> (as-url (java.io.File. "/tmp")) 22 | # 23 | user> (as-url (java.net.URI. "http://www.google.com")) 24 | # 25 | user> (as-url "baidu.com") 26 | ;;MalformedURLException no protocol: baidu.com java.net.URL. (URL.java:567) 27 | -------------------------------------------------------------------------------- /clojure.core/rsubseq.rst: -------------------------------------------------------------------------------- 1 | rsubseq 2 | ------------- 3 | 4 | | **(rsubseq sc test key)** 5 | | **(rsubseq sc start-test start-key end-test end-key)** 6 | 7 | 用法和 `subseq` 函数一样,但是返回的序列是逆序排序的。 8 | 9 | 等同于执行 ``(rseq (subseq sc test key))`` 或者 ``(rseq (subseq sc start-test start-key end-test end-key))`` 。 10 | 11 | :: 12 | 13 | ; 测试数据 14 | 15 | user=> (def numbers (sorted-map 1 "one" 2 "two" 3 "three" 4 "four" 5 "five")) 16 | #'user/numbers 17 | 18 | user=> numbers 19 | {1 "one", 2 "two", 3 "three", 4 "four", 5 "five"} 20 | 21 | 22 | ; 过滤所有键小于 1 大于 4 的键-值对,并逆序地返回结果 23 | 24 | user=> (rsubseq numbers >= 2 <= 4) 25 | ([4 "four"] [3 "three"] [2 "two"]) 26 | 27 | 28 | ; 过滤所有键小于 2 的键-值对,并逆序地返回结果 29 | 30 | user=> (rsubseq numbers > 2) 31 | ([5 "five"] [4 "four"] [3 "three"]) 32 | 33 | 34 | -------------------------------------------------------------------------------- /clojure.set/difference.rst: -------------------------------------------------------------------------------- 1 | difference 2 | ============= 3 | 4 | | **(difference s1)** 5 | | **(difference s1 s2)** 6 | | **(difference s1 s2 & sets)** 7 | 8 | 返回集合 ``s1`` 和其余给定集合之间的差。 9 | 10 | 当只有一个参数时,返回该参数。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user> (use 'clojure.set) 17 | nil 18 | 19 | ; 单个集合 20 | 21 | user> (difference #{:a :b :c}) 22 | #{:a :c :b} 23 | 24 | user> (let [s #{:a :b :c}] (identical? s (difference s))) 25 | true 26 | 27 | ; 两个集合 28 | 29 | user> (difference #{:a :b :c} #{:a :b}) 30 | #{:c} 31 | 32 | user> (difference #{:a :b :c} #{:a :b :c}) 33 | #{} 34 | 35 | ; 多个集合 36 | 37 | user> (difference #{:a :b :c} #{:a} #{:b}) 38 | #{:c} 39 | -------------------------------------------------------------------------------- /clojure.java.io/file.rst: -------------------------------------------------------------------------------- 1 | file 2 | ========== 3 | 4 | | **(file arg)** 5 | | **(file parent child)** 6 | | **(file parent child & more)** 7 | 8 | 根据参数创建一个 ``java.io.File`` 对象。 9 | 10 | 如果只有一个参数 ``arg`` ,返回对应的 ``java.io.File`` 对象。 11 | 12 | 如果有多个参数,第一个参数 ``parent`` 作为根目录;后续参数作为每一层子目录或文件,且必须是用相对路径表示的。 13 | 14 | ``parent`` , ``child`` 和 ``more`` 类型可以是 ``java.lang.String`` , ``java.io.File`` , ``java.net.URL`` 或者 ``java.net.URI`` 。 15 | 16 | :: 17 | 18 | user> (use 'clojure.java.io) 19 | nil 20 | user> (file "/tmp") 21 | # 22 | user> (file "/tmp" "a" "b") 23 | # 24 | user> (file "/tmp" "a" (java.io.File. "../b")) 25 | # 26 | user> (file (java.net.URL. "file:///tmp") "a" (java.io.File. "../b")) 27 | # 28 | -------------------------------------------------------------------------------- /clojure.java.io/input-stream.rst: -------------------------------------------------------------------------------- 1 | input-stream 2 | ============== 3 | 4 | | **(input-stream x & opts)** 5 | 6 | 7 | 根据 ``x`` 创建一个 ``java.io.BufferedInputStream`` 。 8 | 9 | ``x`` 可以是 ``java.io.InputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` , ``byte`` 数组或者 ``char`` 数组 。 10 | 11 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 12 | 13 | ``opts`` 定义创建选项,key可以是 ``:append`` 和 ``:encoding`` 。 14 | 15 | :: 16 | 17 | user> (use 'clojure.java.io) 18 | nil 19 | user> (input-stream (java.io.File. "/tmp/x")) 20 | ;;# 21 | user> (input-stream (java.io.File. "/tmp/x") :encoding "UTF-8") 22 | ;;# 23 | -------------------------------------------------------------------------------- /clojure.java.io/copy.rst: -------------------------------------------------------------------------------- 1 | copy 2 | ============= 3 | 4 | | **(copy input output & opts)** 5 | 6 | 把 ``input`` 的内容拷贝到 ``output`` ,成功返回 ``nil`` ,失败抛出 ``IOException`` 。 7 | 8 | ``input`` 可以是 ``java.io.InputStream`` , ``java.io.Reader`` , ``java.io.File`` , ``byte`` 数组,或者 ``java.lang.String`` 。当输入是 ``java.lang.String`` 的时候,是把字符串本身拷贝到输出。 9 | 10 | ``output`` 可以是 ``java.io.OutputStream`` , ``java.io.Writer`` 或者 ``java.io.File`` 。 11 | 12 | ``opts`` 可以包含 ``:buffer-size`` 和 ``encoding`` 。 ``:buffer-size`` 默认1024。 13 | 14 | 除了自己打开的, ``copy`` 不会关闭任何流。 15 | 16 | 17 | :: 18 | 19 | user> (use 'clojure.java.io) 20 | nil 21 | user> (copy "XXXXXX" (output-stream "/tmp/x")) 22 | nil 23 | user> (slurp "/tmp/x") 24 | "XXXXXX" 25 | user> (copy (file "/tmp/x") (output-stream "/tmp/xx")) 26 | nil 27 | user> (slurp "/tmp/x") 28 | "XXXXXX" 29 | -------------------------------------------------------------------------------- /clojure.core/delay.rst: -------------------------------------------------------------------------------- 1 | delay 2 | ====== 3 | 4 | **(delay & body)** 5 | 6 | 参数 ``body`` 接受一系列表达式,并返回一个 ``Delay`` 对象。 7 | 8 | 这个 ``Delay`` 对象只有在第一次被 ``force`` 函数、 ``deref`` 函数或者 ``@`` 宏强迫求值时,才会对 ``body`` 进行求值。 9 | 10 | ``body`` 的求值结果会被缓存,之后对这个 ``Delay`` 对象的所有强迫求值,都返回这个缓存结果。 11 | 12 | `查看源码 `_ 13 | 14 | :: 15 | 16 | user=> (def d (delay (println "force delay object") 17 | (+ 1 1))) 18 | #'user/d 19 | 20 | user=> d 21 | # 22 | 23 | user=> @d 24 | force delay object ; 第一次强迫求值 25 | 2 ; 这个值会被缓存 26 | 27 | user=> @d 28 | 2 ; 不再求值 body ,只返回缓存值 29 | 30 | user=> d 31 | # ; 打印值现在带有 body 的值 32 | -------------------------------------------------------------------------------- /clojure.core/conj.rst: -------------------------------------------------------------------------------- 1 | conj 2 | -------- 3 | 4 | | **(conj coll x)** 5 | | **(conj coll x & xs)** 6 | 7 | ``conj`` 的完整词义是 conjoin , 8 | 表示『相连接』的意思, 9 | 它用于将元素和 collection 拼接起来。 10 | 11 | 需要注意的是, 12 | 根据 ``coll`` 的类型, 13 | 组合会发生在 ``coll`` 的不同地方, 14 | 也即是, 元素 ``x`` 可能会被加入到 ``coll`` 的最左边,也可能会被加入到最右边。 15 | 16 | 当 ``coll`` 等于 ``nil`` , 17 | 也即是,执行 ``(conj nil item)`` 时, 18 | 结果为 ``(item)`` 。 19 | 20 | :: 21 | 22 | ; coll 为 nil 23 | 24 | user=> (conj nil 1) 25 | (1) 26 | 27 | 28 | ; 向量的组合在尾部进行 29 | 30 | user=> (conj [0 1 2] 3) 31 | [0 1 2 3] 32 | 33 | 34 | ; 列表的组合在头部进行 35 | 36 | user=> (conj (list 0 1 2) 3) 37 | (3 0 1 2) 38 | 39 | 40 | ; 处理多个元素的 conj 41 | ; 注意向量和列表的结果之间的不同 42 | 43 | user=> (conj [0 1 2] 3 4 5) 44 | [0 1 2 3 4 5] 45 | 46 | user=> (conj (list 0 1 2) 3 4 5) 47 | (5 4 3 0 1 2) 48 | 49 | 50 | -------------------------------------------------------------------------------- /clojure.core/dissoc.rst: -------------------------------------------------------------------------------- 1 | dissoc 2 | ---------- 3 | 4 | | **(dissoc map)** 5 | | **(dissoc map key)** 6 | | **(dissoc map key & keys)** 7 | 8 | dissoc 表示 dissociate 的意思。 9 | 10 | ``dissoc`` 接受一个 Map ,以及任意个数的 ``key`` , 11 | 返回一个和传入 Map 类型相同的新 Map , 12 | 这个新 Map 不包含所有给定 ``key`` 的映射。 13 | 14 | :: 15 | 16 | user=> (dissoc {:clojure "Rich" :python "Guido"}) ; 没有传入 key 17 | {:python "Guido", :clojure "Rich"} 18 | 19 | user=> (dissoc {:clojure "Rich" :python "Guido"} :python) ; 传入单个 key 20 | {:clojure "Rich"} 21 | 22 | user=> (dissoc {:clojure "Rich" :python "Guido"} :ruby) ; 传入一个不存在于 Map 的 key 23 | {:python "Guido", :clojure "Rich"} 24 | 25 | user=> (dissoc {:clojure "Rich" :python "Guido" :ruby "Matz"} :python :ruby) ; 传入多个 key 26 | {:clojure "Rich"} 27 | 28 | 29 | -------------------------------------------------------------------------------- /clojure.core/import.rst: -------------------------------------------------------------------------------- 1 | import 2 | ------------- 3 | 4 | **(import & import-symbols-or-lists)** 5 | 6 | **import-list => (package-symbol class-name-symbols*)** 7 | 8 | 对于 ``class-name-symbols`` 中的每个 ``name`` 来说, 9 | 将名字为 ``package.name`` 的类添加到当前 namespace 当中。 10 | 11 | 可以在 ``ns`` 宏中通过 ``:import`` 来调用这个函数。 12 | 13 | :: 14 | 15 | user=> (import java.util.Date) ; 载入单个类 16 | java.util.Date 17 | 18 | user=> (str (Date.)) 19 | "Wed Jun 20 23:18:42 CST 2012" 20 | 21 | user=> (import '(java.util Date Calendar) ; 载入多个类 22 | '(java.net URI ServerSocket)) 23 | java.net.ServerSocket 24 | 25 | user=> (ns foo.bar ; 在 ns 宏中使用 26 | (:import (java.util Date Calendar) 27 | (java.net URI ServerSocket))) 28 | java.net.ServerSocket 29 | 30 | 31 | -------------------------------------------------------------------------------- /clojure.java.io/output-stream.rst: -------------------------------------------------------------------------------- 1 | output-stream 2 | ============== 3 | 4 | | **(output-stream x & opts)** 5 | 6 | 根据 ``x`` 创建 ``java.io.BufferedOutputStream`` 。 7 | 8 | ``x`` 可以是 ``java.io.BufferOutputStream`` , ``java.io.OutputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` 。 9 | 10 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 11 | 12 | 当 ``x`` 是 ``java.net.URL`` 和 ``java.net.URI`` 时,协议必须是 ``file`` 。 13 | 14 | ``opt`` 定义创建选项,key可以是 ``:append`` 和 ``:encoding`` 。 15 | 16 | :: 17 | 18 | user> (use 'clojure.java.io) 19 | nil 20 | user> (input-stream (as-file "/tmp/x")) 21 | ;;# 22 | user> (input-stream (as-file "/tmp/x") :append true) 23 | ;;# 24 | -------------------------------------------------------------------------------- /clojure.java.io/make-output-stream.rst: -------------------------------------------------------------------------------- 1 | make-output-stream 2 | ========================= 3 | 4 | | **(make-output-stream x opts)** 5 | 6 | 根据 ``x`` 创建 ``java.io.BufferedOutputStream`` 。 7 | 8 | ``x`` 可以是 ``java.io.BufferOutputStream`` , ``java.io.OutputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` 。 9 | 10 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 11 | 12 | 当 ``x`` 是 ``java.net.URL`` 和 ``java.net.URI`` 时,协议必须是 ``file`` 。 13 | 14 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 15 | 16 | :: 17 | 18 | user> (use 'clojure.java.io) 19 | nil 20 | user> (make-output-stream "/tmp/x" {}) 21 | ;;# 22 | user> (make-output-stream (file "/tmp/x") {}) 23 | ;;# 24 | -------------------------------------------------------------------------------- /clojure.data/diff.rst: -------------------------------------------------------------------------------- 1 | diff 2 | --------------- 3 | 4 | **(diff a b)** 5 | 6 | 递归比较a和b,返回一个tuple 结构如 7 | [只在a中出现的元素 只在b中出现的元素 a和b中共同出现的元素] 8 | 9 | 比较规则: 10 | * a和b相等 返回[nil,nil,a] 11 | * Map键值相同值不同视为不同 12 | * Set无法比较差异 13 | * 所有的序列都被视为索引的关联集合,结果以向量的类型返回 14 | * 所有东西(包含string)都视为原子且平等比较 15 | 16 | :: 17 | 18 | (use 'clojure.data) 19 | (def uno {:same "same", :different "one"}) 20 | (def dos {:same "same", :different "two", :onlyhere "whatever"}) 21 | (diff uno dos) 22 | => ({:different "one"} {:onlyhere "whatever", :different "two"} {:same "same"}) 23 | ;; {uno中出现的元素 } { dos中出现的元素 } {两者均有的元素} 24 | 25 | (diff {:a 1} {:a 1 :b 2}) 26 | => (nil {:b 2} {:a 1}) 27 | ;; 并没有只在第一个集合中存在的元素 28 | 29 | 30 | (diff [1 2 3] [5 9 3 2 3 7]) ;;=> [[1 2] [5 9 nil 2 3 7] [nil nil 3]] 31 | (diff (set [1 2 3]) (set [5 9 3 2 3 7])) ;;=> [#{1} #{7 9 5} #{3 2}] 32 | 33 | 34 | -------------------------------------------------------------------------------- /clojure.core/future.rst: -------------------------------------------------------------------------------- 1 | .. _future: 2 | 3 | future 4 | ========= 5 | 6 | **(future & body)** 7 | 8 | 参数 ``body`` 接受一系列表达式,并返回一个 ``future`` 对象,使用 ``deref`` 或者 ``@`` 可以对这个对象进行强迫求值。 9 | 10 | ``future`` 对象会在另一个线程里对 ``body`` 进行求值,并将求值结果保存到缓存中,之后对这个 ``future`` 对象的所有强迫求值都会返回这个缓存值。 11 | 12 | 如果强迫求值时 ``body`` 的计算还没完成,那么调用者将被阻塞,直到计算完成,或者 ``deref`` 设置的过期时间到达为止。 13 | 14 | :: 15 | 16 | ; 普通的 future 调用 17 | 18 | user=> (def f (future (+ 1 1))) 19 | #'user/f 20 | 21 | user=> f 22 | # 23 | 24 | user=> @f 25 | 2 26 | 27 | ; 一个停滞 5 秒的 future 调用 28 | 29 | user=> @(future (println "start sleep") (Thread/sleep 5000) 10086) 30 | start sleep 31 | 10086 32 | 33 | ; 一个带 timeout 的 deref 调用的例子,防止阻塞时间过长 34 | 35 | user=> (deref (future (Thread/sleep 10000000000000000)) 36 | 1000 37 | "reach block timeout") ; 停滞 1 秒之后返回字符串值 38 | "reach block timeout" 39 | -------------------------------------------------------------------------------- /clojure.core/problem-of-pcalls-and-pvalues.rst: -------------------------------------------------------------------------------- 1 | .. note:: 2 | 3 | 因为 ``pcalls`` 和 ``pvalues`` 的返回值都是惰性序列,因此,如果有一个非常耗时的表达式阻塞在其他一些表达式的前面,那么就算后面的这些表达式已经计算完了,它们也不能被返回。 4 | 5 | 以下是这样一个实例,在序列前面的三个元素,可以立即被返回,但是,后面的三个元素只有等待 ``(Thread/sleep 3000)`` 执行完毕之后,才会被返回,尽管它们早就在并发线程里被求值完了: 6 | 7 | :: 8 | 9 | user=> (for [i (pvalues 1 2 3 10 | (Thread/sleep 3000) 11 | (do (println "eval 4") 4) 12 | (do (println "eval 5") 5) 13 | (do (println "eval 6") 6)) 14 | ] 15 | (println i) 16 | ) 17 | (1 18 | 2 19 | nil eval 5 ; 从 println 的输出可以看到 20 | eval 4 ; 4 、 5 、 6 三个数已经被计算出来了,但还没办法返回 21 | 3 22 | nil eval 6 23 | nil ; sleep 执行,停滞 3 秒 24 | nil 4 25 | nil 5 26 | nil 6 27 | nil nil) 28 | -------------------------------------------------------------------------------- /clojure.core/pmap.rst: -------------------------------------------------------------------------------- 1 | pmap 2 | ======= 3 | 4 | | **(pmap f coll)** 5 | | **(pmap f coll & colls)** 6 | 7 | ``pmap`` 类似于 ``map`` ,唯一的不同是, ``pmap`` 对函数 ``f`` 的应用是并行的。 8 | 9 | ``pmap`` 的返回值是半惰性的(semi-lazy): 10 | 并行计算总是发生在消耗(consumption)之前, 11 | 不过,计算结果只有在被需要时,才会被 realize 。 12 | 13 | 只有当 ``f`` 为计算密集型函数, 14 | 而且并行获得的性能提升足以抵消并行所需的协调消耗时, 15 | 才应该使用 ``pmap`` 。 16 | 17 | `查看源码 `_ 18 | 19 | :: 20 | 21 | ; 串行运行, 4 个元素,每个等待 3 秒,共等待 12 秒 22 | user=> (time 23 | (dorun 24 | (map (fn [x] (Thread/sleep 3000)) 25 | (range 4)))) 26 | "Elapsed time: 12000.767484 msecs" 27 | nil 28 | 29 | ; 并行运行, 4 个元素,每个等待 3 秒,共等待 3 秒 30 | user=> (time 31 | (dorun 32 | (pmap (fn [x] (Thread/sleep 3000)) 33 | (range 4)))) 34 | "Elapsed time: 3002.602211 msecs" 35 | nil 36 | -------------------------------------------------------------------------------- /clojure.core/reduce.rst: -------------------------------------------------------------------------------- 1 | reduce 2 | =========== 3 | 4 | | **(reduce f coll)** 5 | | **(reduce f val coll)** 6 | 7 | ``reduce`` 的行为由以下情况定义: 8 | 9 | - 没有给定 ``val`` : 10 | - ``coll`` 为空:以无参数方式调用 ``f`` ,调用所得的值为返回值。 11 | - ``coll`` 只有一个元素:不调用 ``f`` ,直接将那个元素用作返回值。 12 | - ``coll`` 有多于一个元素:将 ``coll`` 的前两个元素应用到 ``f`` ,得到的结果再和 ``coll`` 的第三个元素一起应用到 ``f`` ,以此类推。 13 | - 有给定 ``val`` : 14 | - ``coll`` 为空:不调用 ``f`` ,直接返回 ``val`` 。 15 | - ``coll`` 不为空:将 ``val`` 和 ``coll`` 的第一个元素应用到 ``f`` ,得到的结果再和 ``coll`` 的第二个元素一起应用到 ``f`` ,以此类推。 16 | 17 | ``f`` 应该是一个接受两个参数的函数,如果处理的 ``coll`` 可能为空,那么它还应该能进行无参数调用。 18 | 19 | `查看源码 `_ 20 | 21 | :: 22 | 23 | user=> (reduce + []) ; coll 为空, + 返回无参数调用结果 0 24 | 0 25 | 26 | user=> (reduce + (range 10)) ; coll 不为空 27 | 45 28 | 29 | user=> (reduce + 0 (range 10)) ; coll 不为空,且给定 val 30 | 45 31 | 32 | -------------------------------------------------------------------------------- /clojure.core/rseq.rst: -------------------------------------------------------------------------------- 1 | rseq 2 | --------- 3 | 4 | **(rseq rev)** 5 | 6 | 在常数时间内,返回 ``rev`` 的逆序序列。 7 | 8 | ``rev`` 只能是向量或者 sorted-map 。 9 | 10 | ``rev`` 为空时,返回 ``nil`` 。 11 | 12 | :: 13 | 14 | ; 空向量和空 sorted-map 15 | 16 | user=> (rseq []) 17 | nil 18 | 19 | user=> (rseq (sorted-map)) 20 | nil 21 | 22 | 23 | ; 非空向量 24 | 25 | user=> (rseq [1 2 3]) 26 | (3 2 1) 27 | 28 | 29 | ; 非空 sorted-map 30 | 31 | user=> (def alpha (sorted-map :a "apple" :b "boy" :c "cat")) 32 | #'user/alpha 33 | 34 | user=> alpha 35 | {:a "apple", :b "boy", :c "cat"} 36 | 37 | user=> (rseq alpha) 38 | ([:c "cat"] [:b "boy"] [:a "apple"]) 39 | 40 | 41 | ; 一些不能处理的情况 42 | 43 | user=> (rseq (list 1 2 3)) 44 | ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Reversible clojure.core/rseq (core.clj:1480) 45 | 46 | user=> (rseq nil) 47 | NullPointerException clojure.core/rseq (core.clj:1480) 48 | -------------------------------------------------------------------------------- /clojure.core/line-seq.rst: -------------------------------------------------------------------------------- 1 | line-seq 2 | ------------ 3 | 4 | **(line-seq rdr)** 5 | 6 | 返回一个惰性序列, 7 | 序列里包含从文件 ``rdr`` 中读出的所有字符串行。 8 | 9 | ``rdr`` 必须是一个 ``java.io.BufferedReader`` 对象。 10 | 11 | :: 12 | 13 | ; 引入 reader 函数,它可以创建一个 java.io.BufferedReader 对象 14 | ; 读出 animal.txt 文件中的所有内容,之后再将文件联接关闭 15 | 16 | user=> (use '[clojure.java.io :only [reader]]) 17 | nil 18 | 19 | user=> (def animal (reader "animal.txt")) 20 | #'user/animal 21 | 22 | user=> (line-seq animal) 23 | ("dog" "cat" "monkey" "lion" "tiger" "dolphin") 24 | 25 | user=> (.close animal) 26 | nil 27 | 28 | 29 | ; 用 with-open 来自动处理文件的打开和关闭 30 | ; 并用更美观的方式打印 animal.txt 文件的内容 31 | 32 | user=> (with-open [animal (reader "animal.txt")] 33 | (let [all-animal (line-seq animal)] 34 | (doseq [a all-animal] 35 | (println a)))) 36 | dog 37 | cat 38 | monkey 39 | lion 40 | tiger 41 | dolphin 42 | nil 43 | -------------------------------------------------------------------------------- /clojure.core/subseq.rst: -------------------------------------------------------------------------------- 1 | subseq 2 | --------- 3 | 4 | | **(subseq sc test key)** 5 | | **(subseq sc start-test start-key end-test end-key)** 6 | 7 | 过滤 ``sc`` 并返回一个序列,序列里的所有实体(entry)的键 ``ek`` 都必须符合条件 ``(true? (test (.. sc comparator (compare ek key)) 0))`` 。 8 | 9 | 如果没有任何实体符合条件,则返回 ``nil`` 。 10 | 11 | 参数 ``sc`` 必须是一个 sorted collection ,测试条件 ``test`` 可以是 ``<`` 、 ``<=`` 、 ``>`` 或者 ``>=`` 。 12 | 13 | :: 14 | 15 | ; 测试数据 16 | 17 | user=> (def numbers (sorted-map 1 "one" 2 "two" 3 "three" 4 "four" 5 "five")) 18 | #'user/numbers 19 | 20 | user=> numbers 21 | {1 "one", 2 "two", 3 "three", 4 "four", 5 "five"} 22 | 23 | 24 | ; 过滤所有键小于 3 的键-值对 25 | 26 | user=> (subseq numbers >= 3) 27 | ([3 "three"] [4 "four"] [5 "five"]) 28 | 29 | 30 | ; 过滤所有键小于 1 大于 4 的键-值对 31 | 32 | user=> (subseq numbers >= 2 <= 4) 33 | ([2 "two"] [3 "three"] [4 "four"]) 34 | 35 | 36 | ; 过滤所有键小于 10 的键-值对,返回 nil 37 | 38 | user=> (subseq numbers >= 10) 39 | nil 40 | -------------------------------------------------------------------------------- /clojure.core/assoc.rst: -------------------------------------------------------------------------------- 1 | assoc 2 | -------- 3 | 4 | | **(assoc map key val)** 5 | | **(assoc map key val & kvs)** 6 | 7 | assoc 表示 associate 的意思。 8 | 9 | ``assoc`` 接受一个 Map ,还有一个或多个 ``key-val`` 对, 10 | 返回一个和传入 Map 类型相同的新 Map , 11 | 除了原来传入 Map 已有的数据外, 12 | 新 Map 还包含传给 ``assoc`` 的那些 ``key-val`` 对。 13 | 14 | 当一个向量被应用到 ``assoc`` 函数时, 15 | 返回一个新向量, 16 | 新向量的索引下标(index) ``key`` 的值就是 ``val`` 。 17 | 18 | 注意索引下标必须 ``<= (count vector)`` 。 19 | 20 | :: 21 | 22 | user=> (assoc {} :Clojure "Rich") 23 | {:Clojure "Rich"} 24 | 25 | user=> (assoc {:Clojure "Rich"} :Clojure "Rich Hickey") ; 如果有同名 key ,那么那么覆盖它 26 | {:Clojure "Rich Hickey"} 27 | 28 | user=> (assoc [1 2 3] 0 10086) 29 | [10086 2 3] 30 | 31 | user=> (assoc [1 2 3] 3 10086) ; key 最大可以等于 (count vector) 32 | [1 2 3 10086] 33 | 34 | user=> (assoc [1 2 3] 10086 10086) ; key 不能大于 (count vector) 35 | IndexOutOfBoundsException clojure.lang.PersistentVector.assocN 36 | (PersistentVector.java:136) 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /clojure.string/replace.rst: -------------------------------------------------------------------------------- 1 | replace 2 | -------------- 3 | 4 | **(replace s match replacement)** 5 | 6 | 将字符串 ``s`` 中的所有 ``match`` 实例(instance)替换成 ``replacement`` 。 7 | 8 | ``match`` / ``replacement`` 可以是以下组合: 9 | 10 | 1. 字符串 / 字符串 11 | 12 | 2. 字符 / 字符 13 | 14 | 3. 模式(pattern) / 字符串或一个函数,其中函数的参数为模式所匹配的实例 15 | 16 | :: 17 | 18 | ; 组合 1 :用字符串替换字符串 19 | ; 将字符串里的子串 moto 替换成 google 20 | 21 | user=> (clojure.string/replace "hello moto" "moto" "google") 22 | "hello google" 23 | 24 | ; 组合 2 :用字符替换字符 25 | ; 将字符串的所有小写 o 替换成大写 O 26 | 27 | user=> (clojure.string/replace "hello moto" "o" "O") 28 | "hellO mOtO" 29 | 30 | ; 组合 3 :用字符串替换匹配模式的实例 31 | ; 将匹配 #"red" 模式的实例替换为 "blue" 32 | 33 | user=> (clojure.string/replace "The color is red" #"red" "blue") 34 | "The color is blue" 35 | 36 | ; 另一个组合 3 :用给定函数的返回值来替换匹配模式的实例 37 | ; 将字符串里的所有原音字母转换为大写 38 | 39 | user=> (clojure.string/replace "The color is red" #"[aeiou]" clojure.string/upper-case) 40 | "ThE cOlOr Is rEd" 41 | -------------------------------------------------------------------------------- /clojure.core/partial.rst: -------------------------------------------------------------------------------- 1 | partial 2 | ------------ 3 | 4 | | **(partial f arg1)** 5 | | **(partial f arg1 arg2)** 6 | | **(partial f arg1 arg2 arg3)** 7 | | **(partial f arg1 arg2 arg3 & more)** 8 | 9 | ``partial`` 接受一个函数 ``f`` , 10 | 以及少于正常 ``f`` 所接受参数数量的参数, 11 | 并返回一个匿名函数。 12 | 13 | 当这个匿名函数被调用时, 14 | 传给它的附加参数(additional args)会和之前给定的参数一起, 15 | 传给函数 ``f`` 。 16 | 17 | :: 18 | 19 | user=> (def three-times (partial * 3)) 20 | #'user/three-times 21 | 22 | user=> (three-times 10) ; (* 3 10) 23 | 30 24 | 25 | user=> (three-times 20) ; (* 3 20) 26 | 60 27 | 28 | user=> (defn add-x-y-z [x y z] 29 | (+ x y z)) 30 | #'user/add-x-y-z 31 | 32 | user=> (def add-y-z (partial add-x-y-z 0)) ; x = 0 33 | #'user/add-y-z 34 | 35 | user=> (def add-z (partial add-y-z 1)) ; y = 1 36 | #'user/add-z 37 | 38 | user=> (add-z 2) ; z = 2 39 | 3 ; (+ 0 1 2) 40 | 41 | 42 | -------------------------------------------------------------------------------- /clojure.string/split.rst: -------------------------------------------------------------------------------- 1 | split 2 | ------- 3 | 4 | | **(split s re)** 5 | | **(split s re limit)** 6 | 7 | 根据正则表达式 ``re`` ,对字符串 ``s`` 进行分割,结果所得的一个或多个字符串保存在一个向量里面。 8 | 9 | 可选的 ``limit`` 参数指定最大的分割次数。 10 | 11 | 这个函数不是惰性的。 12 | 13 | :: 14 | 15 | ; 分割 #"\r?\n" 是 clojure.string/split-lines 的定义 16 | 17 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n") 18 | ["hello" "moto" "again"] 19 | 20 | ; 带 limit 参数 21 | 22 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n" 1) 23 | ["hello\nmoto\r\nagain\r\n"] 24 | 25 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n" 2) 26 | ["hello" "moto\r\nagain\r\n"] 27 | 28 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n" 3) 29 | ["hello" "moto" "again\r\n"] 30 | 31 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n" 4) 32 | ["hello" "moto" "again" ""] 33 | 34 | user=> (clojure.string/split "hello\nmoto\r\nagain\r\n" #"\r?\n" 5) 35 | ["hello" "moto" "again" ""] 36 | -------------------------------------------------------------------------------- /clojure.core/letfn.rst: -------------------------------------------------------------------------------- 1 | letfn 2 | ---------- 3 | 4 | | **(letfn fnspecs & body)** 5 | 6 | | **fnspecs ==> (fname [params*] exprs)** 或者 **(fname ([params*] exprs)+)** 7 | 8 | 使用一个函数体 ``body`` ,以及一个带有函数规格(specs)的向量 ``fnspecs`` , 9 | 将向量里的名字和相应的函数进行绑定。 10 | 11 | 向量里的名字在函数定义中,还有函数体内,都是可见的。 12 | 13 | :: 14 | 15 | user=> (letfn [(twice [x] 16 | (* x 2)) 17 | (six-times [y] 18 | (* 3 (twice y)))] 19 | (println "Twice 15 = " (twice 15)) 20 | (println "Six times 15 = " (six-times 15))) 21 | Twice 15 = 30 22 | Six times 15 = 90 23 | nil 24 | 25 | ;; 名字 twice 和 six-times 在离开 letfn 之后不可用 26 | 27 | ;user=> (twice 15) 28 | ;CompilerException java.lang.RuntimeException: Unable to resolve symbol: twice in this context, compiling:(NO_SOURCE_PATH:7) 29 | 30 | ;user=> (six-times 15) 31 | ;CompilerException java.lang.RuntimeException: Unable to resolve symbol: six-times in this context, compiling:(NO_SOURCE_PATH:8) 32 | 33 | 34 | -------------------------------------------------------------------------------- /clojure.java.io/make-input-stream.rst: -------------------------------------------------------------------------------- 1 | make-input-stream 2 | ====================== 3 | 4 | | **(make-input-stream x opts)** 5 | 6 | 根据 ``x`` 创建一个 ``java.io.BufferedInputStream`` 。 7 | 8 | ``x`` 可以是 ``java.io.BufferedInputStream`` , ``java.io.InputStream`` , ``java.io.File`` , ``java.net.URL`` , ``java.net.URI`` , ``java.lang.String`` , ``java.net.Socket`` 或者 ``byte`` 数组。 9 | 10 | 当 ``x`` 是 ``java.lang.String`` 时,会先尝试把 ``x`` 解释成 ``java.net.URL`` ,如果失败,则是 ``java.io.File`` 。 11 | 12 | ``opt`` 是一个map,定义选项,key可以是 ``:append`` 和 ``:encoding`` 。 13 | 14 | 15 | :: 16 | 17 | user> (use 'clojure.java.io) 18 | nil 19 | user> (make-input-stream "/tmp/x" {}) 20 | ;;# 21 | user> (make-input-stream (java.io.File. "/tmp/x") {}) 22 | ;;# 23 | user> (make-input-stream (java.io.File. "/tmp/NO_SUCH_FILE") {}) 24 | ;;FileNotFoundException /tmp/NO_SUCH_FILE (No such file or directory) java.io.FileInputStream.open (FileInputStream.java:-2) 25 | -------------------------------------------------------------------------------- /clojure.repl/pst.rst: -------------------------------------------------------------------------------- 1 | pst 2 | ============= 3 | 4 | | **(pst)** 5 | | **(pst e-or-depth)** 6 | | **(pst e depth)** 7 | 8 | 英文全称为print stack trace 9 | 10 | 打印出最近一次被REPL捕获的异常信息 11 | 12 | 13 | :: 14 | 15 | user=> (/ 1 0) 16 | ;; ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:156) 17 | 18 | user=> (pst) 19 | ;; ArithmeticException Divide by zero 20 | ;; clojure.lang.Numbers.divide (Numbers.java:156) 21 | ;; clojure.lang.Numbers.divide (Numbers.java:3691) 22 | ;; user/eval13 (NO_SOURCE_FILE:7) 23 | ;; clojure.lang.Compiler.eval (Compiler.java:6619) 24 | ;; clojure.lang.Compiler.eval (Compiler.java:6582) 25 | ;; clojure.core/eval (core.clj:2852) 26 | ;; clojure.main/repl/read-eval-print--6588/fn--6591 (main.clj:259) 27 | ;; clojure.main/repl/read-eval-print--6588 (main.clj:259) 28 | ;; clojure.main/repl/fn--6597 (main.clj:277) 29 | ;; clojure.main/repl (main.clj:277) 30 | ;; clojure.main/repl-opt (main.clj:343) 31 | ;; clojure.main/main (main.clj:441) 32 | nil 33 | -------------------------------------------------------------------------------- /clojure.core/->>.rst: -------------------------------------------------------------------------------- 1 | ->> 2 | ====== 3 | 4 | | **(->> x form)** 5 | | **(->> x form & more)** 6 | 7 | 将多个形式串连成一个表达式。 8 | 9 | 如果只有一个参数 ``x`` 和一个形式 ``form`` ,那么将 ``x`` 作为最后一项(item),插入到 ``form`` 当中,如果 ``form`` 不是一个列表,那么将 ``form`` 包裹到一个列表里面。[译注:举个例子, ``(->> a-map :key)`` 会展开成 ``(:key a-map)`` ,而不是 ``:key a-map`` 。] 10 | 11 | 如果有多于一个形式,那么将第一个形式作为最后一项插入到第二个形式中,以此类推。 12 | 13 | `查看源码 `_ 14 | 15 | :: 16 | 17 | ; 计算小于 10 的整数的平方之和 18 | 19 | user=> (->> (range) 20 | (map #(* % %)) 21 | (filter even?) 22 | (take 10) 23 | (reduce +)) 24 | 1140 25 | 26 | user=> (use '[clojure.walk :only [macroexpand-all]]) 27 | nil 28 | 29 | user=> (macroexpand-all '(->> (range) 30 | (map #(* % %)) 31 | (filter even?) 32 | (take 10) 33 | (reduce +))) 34 | (reduce + (take 10 (filter even? (map (fn* [p1__3#] (* p1__3# p1__3#)) (range))))) 35 | -------------------------------------------------------------------------------- /clojure.core/-__.rst: -------------------------------------------------------------------------------- 1 | ->> 2 | ====== 3 | 4 | | **(->> x form)** 5 | | **(->> x form & more)** 6 | 7 | 将多个形式串连成一个表达式。 8 | 9 | 如果只有一个参数 ``x`` 和一个形式 ``form`` ,那么将 ``x`` 作为最后一项(item),插入到 ``form`` 当中,如果 ``form`` 不是一个列表,那么将 ``form`` 包裹到一个列表里面。[译注:举个例子, ``(->> a-map :key)`` 会展开成 ``(:key a-map)`` ,而不是 ``:key a-map`` 。] 10 | 11 | 如果有多于一个形式,那么将第一个形式作为最后一项插入到第二个形式中,以此类推。 12 | 13 | `查看源码 `_ 14 | 15 | :: 16 | 17 | ; 计算小于 10 的整数的平方之和 18 | 19 | user=> (->> (range) 20 | (map #(* % %)) 21 | (filter even?) 22 | (take 10) 23 | (reduce +)) 24 | 1140 25 | 26 | user=> (use '[clojure.walk :only [macroexpand-all]]) 27 | nil 28 | 29 | user=> (macroexpand-all '(->> (range) 30 | (map #(* % %)) 31 | (filter even?) 32 | (take 10) 33 | (reduce +))) 34 | (reduce + (take 10 (filter even? (map (fn* [p1__3#] (* p1__3# p1__3#)) (range))))) 35 | -------------------------------------------------------------------------------- /clojure.core/range.rst: -------------------------------------------------------------------------------- 1 | range 2 | --------- 3 | 4 | | **(range)** 5 | | **(range end)** 6 | | **(range start end)** 7 | | **(range start end step)** 8 | 9 | 返回一个惰性序列, 10 | 序列里包含从大于等于 ``start`` 到小于 ``end`` 11 | 区间内的所有数字(``start <= numbers < end``), 12 | 数字的步进以 ``step`` 指定。 13 | 14 | 默认情况下, ``start`` 为 ``0`` , ``step`` 为 ``1`` ,而 ``end`` 则为无限。 15 | 16 | :: 17 | 18 | ; 不指定任何参数,返回一个包含所有非负整数的惰性序列 19 | ; 0, 1, 2, 3 ... 20 | 21 | user=> (take 3 (range)) 22 | (0 1 2) 23 | 24 | user=> (take 10 (range)) 25 | (0 1 2 3 4 5 6 7 8 9) 26 | 27 | 28 | ; 只指定 end 29 | ; 返回大于等于 0 到小于 end 之内的所有整数 30 | 31 | user=> (range 5) 32 | (0 1 2 3 4) 33 | 34 | user=> (range 10) 35 | (0 1 2 3 4 5 6 7 8 9) 36 | 37 | 38 | ; 指定 start 和 end 39 | 40 | user=> (range 5 10) 41 | (5 6 7 8 9) 42 | 43 | user=> (range 0 10) 44 | (0 1 2 3 4 5 6 7 8 9) 45 | 46 | 47 | ; 指定 start 、 end 和 step 48 | ; 第一个惰性序列计算 2 到 20 内的所有偶数 49 | ; 第二个惰性序列计算 1 到 20 内的所有奇数 50 | 51 | user=> (range 2 20 2) 52 | (2 4 6 8 10 12 14 16 18) 53 | 54 | user=> (range 1 20 2) 55 | (1 3 5 7 9 11 13 15 17 19) 56 | 57 | -------------------------------------------------------------------------------- /fixed_width_pyramid/disqus.html: -------------------------------------------------------------------------------- 1 |
2 |

3 | 讨论 4 | 5 |

6 | 7 |
8 | 19 | 20 | comments powered by Disqus 21 |
22 | -------------------------------------------------------------------------------- /clojure.core/deref.rst: -------------------------------------------------------------------------------- 1 | .. _deref: 2 | 3 | deref 4 | ======= 5 | 6 | | **(deref ref)** 7 | | **(deref ref timeout-ms timeout-val)** 8 | 9 | ``deref`` 等同于这些读入器宏(reader macro): ``@ref`` / ``@agent`` / ``@var`` / ``@atom`` / ``@delay`` / ``@future`` / ``@promise`` 。 10 | 11 | 在事务中调用 ``deref`` 时,返回 ``ref`` 的事务值(in-transaction-value);在非事务情况下调用,则返回 ``ref`` 的最近一次提交值(most-recently-committed value). 12 | 13 | 应用于 ``var`` 、 ``agent`` 或 ``atom`` 时,返回它们的当前状态。 14 | 15 | 应用于 ``future`` 时,如果计算尚未完成,那么阻塞。 16 | 17 | 应用于 ``promise`` 时,如果该 ``promise`` 还没用 ``deliver`` 设置过值,那么阻塞。 18 | 19 | 带 ``timeout`` 参数的变种(variant)用于处理 ``future`` 和 ``promise`` 这种可能会阻塞的引用(reference):当阻塞时长超过 ``timeout`` 毫秒,而引用还未有值可用时,返回 ``timeout-val`` 作为值。 20 | 21 | `查看源码 `_ 22 | 23 | :: 24 | 25 | ; 普通的 deref 26 | 27 | user=> (def d (delay (+ 1 1))) 28 | #'user/d 29 | 30 | user=> (deref d) 31 | 2 32 | 33 | user=> @d 34 | 2 35 | 36 | ; 带超时的 deref 37 | 38 | user=> (def p (promise)) 39 | #'user/p 40 | 41 | user=> (deref p 5000 nil) ; 5 秒内没有可用值,就返回 nil 42 | nil 43 | 44 | -------------------------------------------------------------------------------- /clojure.core/map.rst: -------------------------------------------------------------------------------- 1 | map 2 | ===== 3 | 4 | | **(map f coll)** 5 | | **(map f c1 c2)** 6 | | **(map f c1 c2 c3)** 7 | | **(map f c1 c2 c3 & colls)** 8 | 9 | 返回一个惰性序列, 10 | 序列的第一个元素是所有给定 ``collection`` 的第一个元素应用于函数 ``f`` 所得出的返回值, 11 | 序列的第二个元素是所有给定 ``collection`` 的第二个元素应用于函数 ``f`` 所得出的返回值。。。以此类推,一直到给定 ``collection`` 的其中一个被处理完为止。 12 | 13 | 当其中一个 ``collection`` 被处理完之后,其他 ``collection`` 的剩余元素会被忽略,因此结果序列的长度由给定 ``collection`` 中长度最短的那个决定。 14 | 15 | 函数 ``f`` 的参数个数应该和给定 ``collection`` 的数量一致。 16 | 17 | `查看源码 `_ 18 | 19 | :: 20 | 21 | ;; 处理单个 collection 22 | 23 | user=> (range 10) 24 | (0 1 2 3 4 5 6 7 8 9) 25 | 26 | user=> (map inc (range 10)) 27 | (1 2 3 4 5 6 7 8 9 10) 28 | 29 | 30 | ;; 处理两个 collection 31 | 32 | user=> (range 0 10) 33 | (0 1 2 3 4 5 6 7 8 9) 34 | 35 | user=> (reverse (range 0 10)) 36 | (9 8 7 6 5 4 3 2 1 0) 37 | 38 | user=> (map #(+ %1 %2) (range 10) (reverse (range 10))) 39 | (9 9 9 9 9 9 9 9 9 9) 40 | 41 | 42 | ;; 处理长度不同的两个 collection 43 | 44 | user=> (map #(+ %1 %2) (range 10086) (reverse (range 10))) 45 | (9 9 9 9 9 9 9 9 9 9) 46 | 47 | -------------------------------------------------------------------------------- /clojure.core/promise.rst: -------------------------------------------------------------------------------- 1 | .. _promise: 2 | 3 | promise 4 | ========= 5 | 6 | **(promise)** 7 | 8 | *试验版本,将来可能会出现改动。* 9 | 10 | 返回一个 ``promise`` 对象,可以使用 ``deref`` 或者 ``@`` 读取它的值,也可以使用 ``deliver`` 对它进行只能设置一次的赋值。 11 | 12 | 如果 ``promise`` 对象在使用 ``deliver`` 设置值之前,就被 ``deref`` 或者 ``@`` 读取,那么调用者将被阻塞,直到 ``promise`` 对象有值,或者 ``deref`` 设置的超时时间到期为止。 13 | 14 | 被 ``deliver`` 设置值之后,对 ``promise`` 的每次 ``deref`` 或者 ``@`` 都会不阻塞地返回 ``deliver`` 所设置的值。 15 | 16 | `查看源码 `_ 17 | 18 | :: 19 | 20 | user=> (def p (promise)) 21 | #'user/p 22 | 23 | user=> p 24 | # 25 | 26 | ; 对未有值的 promise 进行 deref 27 | ; 为了避免陷入无限阻塞,设置 5 秒的超时时间 28 | 29 | user=> (deref p 5000 "reach timeout") 30 | "reach timeout" 31 | 32 | ; 为 promise 设置值 33 | 34 | user=> (deliver p 10086) 35 | # 36 | 37 | user=> @p 38 | 10086 39 | 40 | user=> p 41 | # 42 | 43 | ; 试试重复 deliver ? 44 | 45 | user=> (deliver p 123123) 46 | nil 47 | 48 | user=> @p 49 | 10086 50 | -------------------------------------------------------------------------------- /clojure.java.javadoc/add-remote-javadoc.rst: -------------------------------------------------------------------------------- 1 | add-remote-javadoc 2 | ======================= 3 | 4 | **(add-remote-javadoc package-prefix url)** 5 | 6 | 添加路径 ``url`` 到远程 javadoc 路径的列表, ``package-prefix`` 是 URL 对应的 javadoc 的包名的开始部分。 7 | 8 | `查看源码 `_ 9 | 10 | 11 | :: 12 | 13 | user=> (use 'clojure.java.javadoc) 14 | nil 15 | 16 | user=> (add-remote-javadoc "org.apache.commons.csv." "http://commons.apache.org/proper/commons-csv/apidocs/index.html") 17 | {"java." "http://java.sun.com/javase/6/docs/api/", "javax." "http://java.sun.com/javase/6/docs/api/", "org.apache.commons.codec." "http://commons.apache.org/codec/api-release/", "org.apache.commons.csv." "http://commons.apache.org/proper/commons-csv/apidocs/index.html", "org.apache.commons.io." "http://commons.apache.org/io/api-release/", "org.apache.commons.lang." "http://commons.apache.org/lang/api-release/", "org.ietf.jgss." "http://java.sun.com/javase/6/docs/api/", "org.omg." "http://java.sun.com/javase/6/docs/api/", "org.w3c.dom." "http://java.sun.com/javase/6/docs/api/", "org.xml.sax." "http://java.sun.com/javase/6/docs/api/"} 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /clojure.set/join.rst: -------------------------------------------------------------------------------- 1 | join 2 | ============= 3 | 4 | | **(join xrel yrel)** 5 | | **(join xrel yrel km)** 6 | 7 | ``join`` 类似于 SQL 中的 ``join`` 操作:它对 ``xrel`` 和 ``yrel`` 做关联操作。 8 | 9 | ``xrel`` 和 ``yrel`` 是两个序列,序列的每个成员都是一个 ``map`` , ``map`` 的每个 key-value 对可以看做数据库表的字段以及对应的值。 10 | 11 | 如果提供了 ``km`` 参数,则按照 ``km`` 所列出的 ``key`` 进行关联。 12 | 13 | .. TODO: 添加一个设置 ``km`` 参数的例子 14 | 15 | `查看源码 `_ 16 | 17 | :: 18 | 19 | user> (use 'clojure.set) 20 | nil 21 | 22 | ;; 处理 set 23 | 24 | user> (def students ;; 学生信息 25 | #{{:id 1 :name "Li Lei"} 26 | {:id 2 :name "Han Meimei"}}) 27 | #'user/students 28 | 29 | user> (def score ;; 学生成绩 30 | #{{:id 1 :score 60} 31 | {:id 2 :score 99}}) 32 | #'user/score 33 | 34 | user> (join students score) ;; 关联信息和成绩 35 | #{{:score 99, :name "Han Meimei", :id 2} 36 | {:score 60, :name "Li Lei", :id 1}} 37 | 38 | ;; 处理 vector 39 | 40 | user> (def score-vec 41 | [{:id 1 :score 60} 42 | {:id 2 :score 99}]) 43 | #'user/score 44 | 45 | user> (join students score-vec) 46 | #{{:score 99, :name "Han Meimei", :id 2} 47 | {:score 60, :name "Li Lei", :id 1}} 48 | -------------------------------------------------------------------------------- /clojure.xml/parse.rst: -------------------------------------------------------------------------------- 1 | parse 2 | =============== 3 | 4 | **(parse s)** 5 | 6 | **(parse s startparse)** 7 | 8 | 解析并加载源 ``s`` , ``s`` 可以是一个文件, ``InputStream`` ,或者一个代表 URL 的字符串。 9 | 10 | 函数返回一棵 ``xml/element`` 类型的 ``struct-map`` 树, 11 | ``struct-map`` 中包含键 ``:tag`` 、 ``:attrs`` 、 ``:content`` , 12 | 以及访问函数 ``tag`` 、 ``attrs`` 、 ``content`` 。 13 | 14 | ``startparse`` 用于指定解释所使用的解释器, 15 | 这个参数的值应该是一个函数: 16 | 函数接受一个源(source)和一个内容处理器(ContentHandler)作为参数, 17 | 并返回一个解释器作为函数的返回值。 18 | 19 | `查看源码 `_ 20 | 21 | 22 | :: 23 | 24 | (require '[clojure.xml :as xml] 25 | '[clojure.zip :as zip]) 26 | 27 | ;;convenience function, first sawn at nakkaya.com later in clj.zip src 28 | (defn zip-str [s] 29 | (zip/xml-zip (xml/parse (java.io.ByteArrayInputStream. (.getBytes s))))) 30 | 31 | ;;parse from xml-strings to internal xml representation 32 | (zip-str "") 33 | => 34 | [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil] 35 | 36 | ;;root can be rendered with xml/emit-element 37 | (xml/emit-element (zip/root [{:tag :a, :attrs {:href "nakkaya.com"}, :content nil} nil])) 38 | => 39 | 40 | ;;printed (to assure it's not lazy and performance), can be catched to string variable with with-out-str 41 | -------------------------------------------------------------------------------- /clojure.core/->.rst: -------------------------------------------------------------------------------- 1 | -> 2 | ===== 3 | 4 | | **(-> x)** 5 | | **(-> x form)** 6 | | **(-> x form & more)** 7 | 8 | 将多个形式串连成一个表达式。 9 | 10 | 如果只有一个参数 ``x`` 和一个形式 ``form`` ,那么将 ``x`` 作为第二个项(item),插入到 ``form`` 当中,如果 ``form`` 不是一个列表,那么将 ``form`` 包裹到一个列表里面。[译注:举个例子, ``(-> a-map :key)`` 会展开成 ``(:key a-map)`` ,而不是 ``:key a-map`` 。] 11 | 12 | 如果有多于一个形式,那么将第一个形式作为第二个项插入到第二个形式中,以此类推。 13 | 14 | `查看源码 `_ 15 | 16 | :: 17 | 18 | ; 应用多个函数 19 | 20 | user=> (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) 21 | "X" 22 | 23 | user=> (use '[clojure.walk :only [macroexpand-all]]) 24 | nil 25 | 26 | user=> (macroexpand-all '(-> "a b c d" 27 | .toUpperCase 28 | (.replace "A" "X") 29 | (.split " ") 30 | first)) 31 | (first (. (. (. "a b c d" toUpperCase) replace "A" "X") split " ")) 32 | 33 | ; 从深层嵌套的 map 中取出值 34 | 35 | user=> (def language {:clojure {:author {:first-name "Rich" :last-name "Hickey"}}}) 36 | #'user/language 37 | 38 | user=> (:first-name (:author (:clojure language))) 39 | "Rich" 40 | 41 | user=> (-> language :clojure :author :first-name) 42 | "Rich" 43 | -------------------------------------------------------------------------------- /clojure.core/-_.rst: -------------------------------------------------------------------------------- 1 | -> 2 | ===== 3 | 4 | | **(-> x)** 5 | | **(-> x form)** 6 | | **(-> x form & more)** 7 | 8 | 将多个形式串连成一个表达式。 9 | 10 | 如果只有一个参数 ``x`` 和一个形式 ``form`` ,那么将 ``x`` 作为第二个项(item),插入到 ``form`` 当中,如果 ``form`` 不是一个列表,那么将 ``form`` 包裹到一个列表里面。[译注:举个例子, ``(-> a-map :key)`` 会展开成 ``(:key a-map)`` ,而不是 ``:key a-map`` 。] 11 | 12 | 如果有多于一个形式,那么将第一个形式作为第二个项插入到第二个形式中,以此类推。 13 | 14 | `查看源码 `_ 15 | 16 | :: 17 | 18 | ; 应用多个函数 19 | 20 | user=> (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) 21 | "X" 22 | 23 | user=> (use '[clojure.walk :only [macroexpand-all]]) 24 | nil 25 | 26 | user=> (macroexpand-all '(-> "a b c d" 27 | .toUpperCase 28 | (.replace "A" "X") 29 | (.split " ") 30 | first)) 31 | (first (. (. (. "a b c d" toUpperCase) replace "A" "X") split " ")) 32 | 33 | ; 从深层嵌套的 map 中取出值 34 | 35 | user=> (def language {:clojure {:author {:first-name "Rich" :last-name "Hickey"}}}) 36 | #'user/language 37 | 38 | user=> (:first-name (:author (:clojure language))) 39 | "Rich" 40 | 41 | user=> (-> language :clojure :author :first-name) 42 | "Rich" 43 | -------------------------------------------------------------------------------- /clojure.core/fn.rst: -------------------------------------------------------------------------------- 1 | fn 2 | ---- 3 | 4 | | **params => positional-params\*** 或者 **positional-params\* & next-param** 5 | | **positional-param => binding-form** 6 | | **next-param => binding-form** 7 | | **name => symbol** 8 | 9 | 定义一个(匿名)函数。 10 | 11 | :: 12 | 13 | user=> (fn greeting [name] ; 创建匿名函数 14 | (str "Hello, " name " .")) 15 | ;# 16 | 17 | user=> ((fn greeting [name] ; 应用匿名函数 18 | (str "hello, " name " .")) 19 | "moto") 20 | "hello, moto ." 21 | 22 | user=> ((fn greeting ; 参数重载(arity overloading) 23 | ([name] 24 | (greeting "Hello" name)) 25 | ([msg name] 26 | (str msg ", " name " ."))) 27 | "moto") 28 | "Hello, moto ." 29 | 30 | user=> ((fn greeting ; 接受不定数量参数的函数 31 | [name & others] 32 | (if (seq others) 33 | (str "Hello, " name " and others: " others " .") 34 | (str "Hello, " name " ."))) 35 | "moto" "nokia" "apple") 36 | "Hello, moto and others: (\"nokia\" \"apple\") ." 37 | 38 | 39 | -------------------------------------------------------------------------------- /clojure.set/index.rst: -------------------------------------------------------------------------------- 1 | index 2 | ========= 3 | 4 | | **(index xrel ks)** 5 | 6 | 7 | ``index`` 类似于 SQL 中的 ``group by`` 操作:它把 ``xrel`` 中的成员按 ``ks`` 中列举的 ``key`` 的值进行分组。 8 | 9 | 其中, ``xrel`` 和 ``ks`` 都是序列(sequence)。 ``xrel`` 的成员是一个个 ``map`` , ``ks`` 的成员是用于分组的 ``key`` 。 10 | 11 | ``index`` 返回一个新 ``map`` ,新 ``map`` 的 ``key`` 是 ``ks`` 的成员作为 ``key`` 在 ``xrel`` 中每个 ``map`` 取到的不同值,新 ``map`` 的 ``value`` 是满足这些值的 ``xrel`` 中成员的集合。 12 | 13 | `查看源码 `_ 14 | 15 | :: 16 | 17 | user> (use 'clojure.set) 18 | nil 19 | 20 | ;; 处理 set 21 | 22 | user> (def points #{{:x 0 :y 0} {:x 0 :y 1} {:x 1 :y 0}}) ;; 定义三个点 23 | #'user/points 24 | 25 | user> (index points [:x]) ;; group by x 坐标 26 | {{:x 1} #{{:y 0, :x 1}}, 27 | {:x 0} #{{:y 1, :x 0} {:y 0, :x 0}}} 28 | 29 | user> (index points [:y :x]) ;; group by x 和 y 坐标 30 | {{:x 1, :y 0} #{{:y 0, :x 1}}, 31 | {:x 0, :y 0} #{{:y 0, :x 0}}, 32 | {:x 0, :y 1} #{{:y 1, :x 0}}} 33 | 34 | user> (index points [:z]) ;; group by 不存在的 z 坐标 35 | {{} #{{:y 1, :x 0} {:y 0, :x 0} {:y 0, :x 1}}} 36 | 37 | ;; 还可以处理 vector 38 | 39 | user> (def points-vec [{:x 0 :y 0} {:x 0 :y 1} {:x 1 :y 0}]) 40 | #'user/points-vec 41 | 42 | user> (index points-vec [:x]) 43 | {{:x 1} #{{:y 0, :x 1}}, {:x 0} #{{:y 1, :x 0} {:y 0, :x 0}}} 44 | -------------------------------------------------------------------------------- /clojure.core/index.rst: -------------------------------------------------------------------------------- 1 | clojure.core 2 | ================= 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | -> 8 | ->> 9 | -_ 10 | -__ 11 | aclone 12 | alength 13 | alter-var-root 14 | assoc 15 | bigdec 16 | bigint 17 | biginteger 18 | comment 19 | comp 20 | compile 21 | complement 22 | concat 23 | cond 24 | conj 25 | cons 26 | constantly 27 | contains 28 | count 29 | counted 30 | declare 31 | defn- 32 | defonce 33 | defprotocol 34 | delay 35 | delay_p 36 | deref 37 | dissoc 38 | distinct 39 | doall 40 | dorun 41 | doseq 42 | empty 43 | even 44 | first 45 | file-seq 46 | filter 47 | fn 48 | future 49 | get 50 | if-let 51 | if-not 52 | import 53 | into 54 | iterate 55 | keep-indexed 56 | keep 57 | key 58 | keys 59 | letfn 60 | line-seq 61 | map-indexed 62 | map 63 | mapcat 64 | max-key 65 | merge 66 | min-key 67 | next 68 | odd 69 | partial 70 | pcalls 71 | pmap 72 | promise 73 | pvalues 74 | range 75 | re-seq 76 | realized 77 | reduce 78 | reductions 79 | remove 80 | repeat 81 | repeatedly 82 | reverse 83 | rseq 84 | rsubseq 85 | seq 86 | shuffle 87 | some 88 | sort 89 | subseq 90 | time 91 | tree-seq 92 | vals 93 | when-let 94 | when-not 95 | with-open 96 | xml-seq 97 | zipmap 98 | -------------------------------------------------------------------------------- /index.rst: -------------------------------------------------------------------------------- 1 | .. Clojure API 文档 documentation master file, created by 2 | sphinx-quickstart on Sun Jun 17 19:46:43 2012. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Clojure API 文档 7 | ========================================== 8 | 9 | .. image:: image/clojure-icon.gif 10 | :align: right 11 | 12 | 这是 Clojure 官方 API 文档 13 | `clojure.github.com/clojure 14 | `_ 15 | 的中文翻译版本。 16 | 17 | 翻译工作目前正在进行中,欢迎加入: 18 | `github.com/huangz1990/clojure_api_cn 19 | `_ 20 | 。 21 | 22 | **目录:** 23 | 24 | .. toctree:: 25 | :maxdepth: 2 26 | 27 | clojure.core/index 28 | clojure.core.async/index 29 | clojure.data/index 30 | clojure.pprint/index 31 | clojure.string/index 32 | clojure.set/ind 33 | clojure.test/index 34 | clojure.java.browse/index 35 | clojure.java.io/index 36 | clojure.java.javadoc/index 37 | clojure.java.shell/index 38 | clojure.xml/index 39 | clojure.repl/index 40 | 41 | 参考资料 42 | ------------ 43 | 44 | Clojure 官方文档: `clojure.org/documentation `_ 45 | 46 | Clojure API 手册: `clojure.github.com/clojure `_ 47 | 48 | Clojure Cheat Sheet: `clojure.org/cheatsheet `_ 49 | 50 | ClojureDocs ,由社区驱动的,带代码示例的 API 手册: `clojuredocs.org `_ 51 | -------------------------------------------------------------------------------- /clojure.core/xml-seq.rst: -------------------------------------------------------------------------------- 1 | xml-seq 2 | ----------- 3 | 4 | **(xml-seq root)** 5 | 6 | 返回一个惰性序列,序列里包含一棵 xml 元素树。 7 | 8 | xml 文件可以用 ``clojure.xml/parse`` 函数解释。 9 | 10 | :: 11 | 12 | ; 解释一个 xml 文件,并提取内容 13 | 14 | user=> (require 'clojure.xml) 15 | nil 16 | 17 | user=> (def content (clojure.xml/parse "http://www.w3schools.com/xml/note.xml")) 18 | #'user/content 19 | 20 | ; 根据 xml 内容,生成 xml 树 21 | 22 | user=> (def tree (xml-seq content)) 23 | #'user/tree 24 | 25 | user=> tree 26 | ({:tag :note, :attrs nil, :content [{:tag :to, :attrs nil, :content ["Tove"]} {:tag :from, :attrs nil, :content ["Jani"]} {:tag :heading, :attrs nil, :content ["Reminder"]} {:tag :body, :attrs nil, :content ["Don't forget me this weekend!"]}]} {:tag :to, :attrs nil, :content ["Tove"]} "Tove" {:tag :from, :attrs nil, :content ["Jani"]} "Jani" {:tag :heading, :attrs nil, :content ["Reminder"]} "Reminder" {:tag :body, :attrs nil, :content ["Don't forget me this weekend!"]} "Don't forget me this weekend!") 27 | 28 | 29 | ; 遍历树 30 | 31 | user=> (nth tree 0) 32 | {:tag :note, :attrs nil, :content [{:tag :to, :attrs nil, :content ["Tove"]} {:tag :from, :attrs nil, :content ["Jani"]} {:tag :heading, :attrs nil, :content ["Reminder"]} {:tag :body, :attrs nil, :content ["Don't forget me this weekend!"]}]} 33 | 34 | user=> (nth tree 1) 35 | {:tag :to, :attrs nil, :content ["Tove"]} 36 | 37 | user=> (nth tree 2) 38 | "Tove" 39 | 40 | user=> (nth tree 3) 41 | {:tag :from, :attrs nil, :content ["Jani"]} 42 | 43 | user=> (nth tree 4) 44 | "Jani" 45 | 46 | 47 | -------------------------------------------------------------------------------- /clojure.core/repeatedly.rst: -------------------------------------------------------------------------------- 1 | repeatedly 2 | ----------------- 3 | 4 | | **(repeatedly f)** 5 | | **(repeatedly n f)** 6 | 7 | 给定一个无参数的函数 ``f`` (通常带有副作用),返回一个调用 ``f`` 函数 ``n`` 次的惰性序列。 8 | 9 | 如果不指定参数 ``n`` ,那么函数 ``f`` 可以执行无限次。 10 | 11 | :: 12 | 13 | ; 测试函数 14 | 15 | user=> (defn greet [] 16 | "hi!") 17 | #'user/greet 18 | 19 | 20 | ; 定义一个执行 10 次 greet 的惰性序列 21 | ; 并用 take 函数取出 5 个和 10 个 greet 的执行结果 22 | 23 | user=> (def ten-greet (repeatedly 10 greet)) 24 | #'user/ten-greet 25 | 26 | user=> (take 5 ten-greet) 27 | ("hi!" "hi!" "hi!" "hi!" "hi!") 28 | 29 | user=> (take 10 ten-greet) 30 | ("hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!") 31 | 32 | 33 | ; 试图取出 10086 个值,但 ten-greet 最多只返回 10 个值 34 | ; 说明取出的数量最多只能和 n 一样大 35 | 36 | user=> (take 10086 ten-greet) 37 | ("hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!") 38 | 39 | 40 | ; 定义一个执行无限次 greet 的惰性序列 41 | 42 | user=> (def infinite-greet (repeatedly greet)) 43 | #'user/infinite-greet 44 | 45 | user=> (take 10 infinite-greet) 46 | ("hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!") 47 | 48 | user=> (take 100 infinite-greet) 49 | ("hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!" "hi!") 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /clojure.pprint/cl-format.rst: -------------------------------------------------------------------------------- 1 | cl-format 2 | ============ 3 | 4 | | **(cl-format writer format-in & args)** 5 | 6 | Common Lisp 兼容的格式输出的函数的实现。cl-format 7 | 的格式包括是输出到流里还是输出 8 | 成string都是通过不同的参数控制的。它支持极为复杂的机构化的数据。 9 | 10 | Writer参数是java.io.Writer的一个实例,有的话输出成流,反之输出成String。format-in 11 | 用于格式控制。 args 指代数据将要被格式化输出的。 12 | 13 | format control string 14 | 是通过格式化符号,标注怎么去把许多参数按不同的方式格式化的。 15 | 类似 String.format 的 dsl。 16 | 17 | 如果 writer 是控制,那么cl-format 返回 string,否则返回空值,输出到流里。 18 | 19 | 一个例子: 20 | (let [results [46 38 22]] 21 | (cl-format true "There ~[are~;is~:;are~]~:* ~d result~:p: ~{~d~^, 22 | ~}~%" 23 | (count results) results)) 24 | 25 | 输出结果 *out*: 26 | There are 3 results: 46, 38, 22 27 | 28 | 详细的文档关于 format control string 在"Common 29 | Lisp the Language, 2nd edition", Chapter 22 30 | (available online at: 31 | http://www.cs.cmu.edu/afs/cs.cmu.edu/project/ai-repository/ai/html/cltl/clm/node200.html#SECTION002633000000000000000) 32 | and in the Common Lisp HyperSpec at 33 | http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm 34 | 35 | 36 | 37 | 1 EXAMPLE 38 | 39 | :: 40 | 41 | ;; 一种格式化integer的方式. 42 | ;; 第一个参数把输出定向到 *out* 43 | user=> (cl-format true "~5d\n" 3) 44 | 3 45 | nil 46 | 47 | ;; 第一个参数nil或false回直接输出成sting 48 | user=> (cl-format nil "~5d" 3) 49 | " 3" 50 | 51 | user=> (cl-format nil "Pad with leading zeros ~5,'0d" 3) 52 | "Pad with leading zeros 00003" 53 | 54 | user=> (cl-format nil "Pad with leading asterisks ~5,'*d" 3) 55 | "Pad with leading asterisks ****3" 56 | 57 | 58 | ;; 如果有办法去描述一个左对齐的数在一个 formatString 里请标示在这理。 59 | ;; 这个任务在我看来,可以首先去 formatted 数成 String 然后再使用 60 | 规则加到原来的输出结果上。 61 | 62 | user=> (cl-format nil "~15a" (cl-format nil "~:d" 1234567)) 63 | "1,234,567 " 64 | 65 | user=> (cl-format nil "Always print the sign ~5@d" 3) 66 | "Always print the sign +3" 67 | 68 | user=> (cl-format nil "Use comma group-separator every 3 digits ~12:d" 1234567) 69 | "Use comma group-separator every 3 digits 1,234,567" 70 | 71 | user=> (cl-format nil "decimal ~d binary ~b octal ~o hex ~x" 63 63 63 63) 72 | "decimal 63 binary 111111 octal 77 hex 3f" 73 | 74 | user=> (cl-format nil "base 7 ~7r with width and zero pad ~7,15,'0r" 63 63) 75 | "base 7 120 with width and zero pad 000000000000120" 76 | 77 | ;; 在 cl-format 里不需要做任何转换 BigInt, 78 | ;; BigInteger, or BigDecimal. 79 | user=> (cl-format nil "cl-format handle BigInts ~15d" 12345678901234567890) 80 | "cl-format handles BigInts 81 | 12345678901234567890" 82 | 83 | user=> (cl-format nil "Be aware of auto-conversion ~8,'0d ~8,'0d" 2.4 -5/4) 84 | "Be aware of auto-conversion 000002.4 85 | 0000-5/4" 86 | 87 | ;; 下面看起来可能像是一个bug,但是是被 Common Lisp HyperSpec 写在文档上的一种方法,如果你觉得这样写不爽, 88 | ;; 你也可以这样写 (format "%08d" -2) 89 | 90 | user=> (cl-format nil "~8,'0d" -2) 91 | "000000-2" 92 | -------------------------------------------------------------------------------- /clojure.core/file-seq.rst: -------------------------------------------------------------------------------- 1 | file-seq 2 | ----------- 3 | 4 | **(file-seq dir)** 5 | 6 | 返回一个惰性序列, 7 | 序列包含给定目录 ``dir`` 的整个目录树 8 | (包括目录中的文件和目录中的文件夹及文件夹里的文件)。 9 | 10 | ``dir`` 必须是一个 ``java.io.File`` 对象。 11 | 12 | :: 13 | 14 | ; 引入 file 函数,它可以根据路径名创建一个 File 对象 15 | ; 我们打开 /tmp 文件夹,并打印它的目录树 16 | 17 | user=> (use '[clojure.java.io :only [file]]) 18 | nil 19 | 20 | user=> (def tmp-folder (file "/tmp")) 21 | #'user/tmp-folder 22 | 23 | user=> (file-seq tmp-folder) 24 | (# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #) 25 | 26 | 27 | ; 使用 doseq 、 sort 和 println 函数 28 | ; 打印一个更美观的、经过排序的目录树 29 | 30 | user=> (doseq [f (sort (file-seq tmp))] 31 | (println f)) 32 | # 33 | # 34 | # 35 | # 36 | # 37 | # 38 | # 39 | # 40 | # 41 | # 42 | # 43 | # 44 | # 45 | # 46 | # 47 | # 48 | # 49 | # 50 | # 51 | # 52 | # 53 | # 54 | # 55 | # 56 | # 57 | # 58 | # 59 | # 60 | # 61 | # 62 | # 63 | # 64 | # 65 | # 66 | # 67 | # 68 | # 69 | nil 70 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | 关于 2 | ==== 3 | 4 | 这是 Clojure 官方 API 文档 5 | `clojure.github.com/clojure 6 | `_ 7 | 的中文翻译版本。 8 | 9 | 在线阅读地址: `clojure-api-cn.readthedocs.org 10 | `_ 。 11 | 12 | 13 | 翻译进度 14 | ----------- 15 | 16 | .. 以下是译者链接: 17 | 18 | .. _huangz: http://huangz.me/ 19 | 20 | .. _Qiu Xiafei: http://chunyemen.org/ 21 | 22 | .. _Lin Xiangyu: http://linxiangyu.org/ 23 | 24 | .. _yfwu: https://github.com/yfwu 25 | 26 | .. _simlegate: https://github.com/simlegate 27 | 28 | .. _sectic: https://github.com/sectic 29 | 30 | .. _yaphet: https://github.com/darionyaphet 31 | 32 | ================================ ============= ===================================================== 33 | 模块 进度 译者 34 | ================================ ============= ===================================================== 35 | ``clojure.core`` 进行中 `huangz`_ , `Lin Xiangyu`_ , `yaphet`_ 36 | ``clojure.data`` 无 37 | ``clojure.inspector`` 无 38 | ``clojure.java.browse`` 已完成 `Lin Xiangyu`_ 39 | ``clojure.java.io`` 已完成 `Qiu Xiafei`_ 40 | ``clojure.java.javadoc`` 已完成 `Lin Xiangyu`_ 41 | ``clojure.java.shell`` 已完成 `Lin Xiangyu`_ 42 | ``clojure.main`` 无 43 | ``clojure.pprint`` 进行中 `sectic`_ 44 | ``clojure.reflect`` 无 45 | ``clojure.repl`` 进行中 `simlegate`_ 46 | ``clojure.set`` 已完成 `Qiu Xiafei`_ 47 | ``clojure.stacktrace`` 无 48 | ``clojure.string`` 已完成 `huangz`_ 49 | ``clojure.template`` 无 50 | ``clojure.test`` 进行中 `yfwu`_ 51 | ``clojure.walk`` 无 52 | ``clojure.xml`` 已完成 `Lin Xiangyu`_ 53 | ``clojure.zip`` 无 54 | ================================ ============= ===================================================== 55 | 56 | 57 | 如何加入翻译? 58 | ---------------- 59 | 60 | 1. 选定你要翻译的函数/宏/模块,到\ `项目 github 的 issue 页面 `_\ 开一个 issue ,将你要翻译的内容写下来(为避免出现多人翻译同一项内容的情况,请确保你要翻译的内容没有其他人在翻译)。 61 | 2. 如果你要翻译的是一整个模块的内容,请在“翻译进度”表中将相应模块的进度从“无”更改为“进行中”,并在“译者”一栏加上你的名字和链接。 62 | 3. 开始翻译! 63 | 4. 完成,提交翻译到 repo ,并在“翻译进度”表中将相应模块的状态改为“已完成”。 64 | 5. ``(recur step-1)`` 65 | 66 | 以下是一些翻译时需要注意的地方: 67 | 68 | * 庞大的 ``clojure.core`` 模块需要多人来共同翻译,只要里面的某个函数/宏没有别人在翻译,你就可以翻译它。 69 | * 最好以单个函数/宏为单位,小段小段地 push 自己的翻译,不要将大一块翻译凑到一起来 push ,小段的内容更容易被检查 70 | * 碰到不好翻译的地方,或者需要任何帮助,开 issue 讨论 71 | * 对于一些没有标准翻译的词语,请使用“翻译(原文)”的格式做标记,比如: 柯里化(currying) 。这种标记同一个页面里做一次就可以了。 72 | * 如果模块文档没有提供相应的测试代码,可以参考 `ClojureDocs `_ 上面的测试代码,也可以自己添加测试代码。 73 | 74 | 对以上规则有任何疑问或建议,请开 issue 或者联系 `huangz`_ 。 75 | 76 | 参考资料 77 | ------------ 78 | 79 | Clojure 官方文档: `clojure.org/documentation `_ 80 | 81 | Clojure API 手册: `clojure.github.com/clojure `_ 82 | 83 | Clojure Cheat Sheet: `clojure.org/cheatsheet `_ 84 | 85 | ClojureDocs ,由社区驱动的,带代码示例的 API 手册: `clojuredocs.org `_ 86 | -------------------------------------------------------------------------------- /clojure.java.shell/sh.rst: -------------------------------------------------------------------------------- 1 | .. _sh: 2 | 3 | sh 4 | ============== 5 | 6 | **(sh & args)** 7 | 8 | 9 | 传递给出的字符串到 ``Runtime.exec()`` 来启动一个子进程。 10 | 11 | 选项有: 12 | 13 | - ``:in`` :给出下列合法的输入源给 ``clojure.java.io/copy`` , 比如, ``InputStream`` , ``Reader`` , ``File`` , ``byte[]`` 或者 ``String`` , 来提供子进程的标准输入(stdin)。 14 | 15 | - ``:in-enc`` :给出一个字符串。作为字符的编码名(比如, ``UTF-8`` 或者 ``ISO-8859-1``\ )来转换 ``:in`` 中给定的字符串的编码,默认是 ``UTF-8`` 。 如果 ``:in`` 给出的字节数组(byte array), 那么它不会被解码,这个选项会被忽略。 16 | 17 | - ``:out-enc`` :选项可以是一个 ``:bytes`` 或者一个 ``String`` , 如果给出的是一个 ``String`` , 它会被当作一个字符编码的名字,(比如, ``UTF-8`` 或者 ``ISO-8859-1``\ )来转换子进程的标准输出的字符串编码,如果给出的是 ``:bytes`` , 子进程的标准输出会被存储到一个字节数组返回,默认是 ``UTF-8`` 。 18 | 19 | - ``:env`` :用一个 map 重载进程的环境变量(env),如果你是一个受虐狂,你可以用一个 ``String[]`` 。 20 | 21 | - ``:dir`` :用一个 ``String`` 或者 ``java.io.File`` 重载进程工作目录(dir) 22 | 23 | 你可以用 ``with-sh-env`` 或者 ``with-sh-dir`` 绑定 ``:env`` 或者 ``:dir`` 到多个操作。 24 | 25 | ``sh`` 返回一个 map : 26 | 27 | - ``:exit`` :子进程的返回码 28 | - ``:out`` :子进程的标准输出(stdout)(\ ``byte[]`` 或者 ``String``\ ) 29 | - ``:err`` :子进程的标准错误(stderr)(用平台默认的编码的 ``String``\ ) 30 | 31 | `查看源码 `_ 32 | 33 | :: 34 | 35 | 36 | user=> (use '[clojure.java.shell :only [sh]]) 37 | 38 | ;; Note: The actual output you see from a command like this will look messier. 39 | ;; The output below has had all newline characters replaced with line 40 | ;; breaks. You would see a big long string with \n characters in the middle. 41 | user=> (sh "ls" "-aul") 42 | 43 | {:exit 0, 44 | :out "total 64 45 | drwxr-xr-x 11 zkim staff 374 Jul 5 13:21 . 46 | drwxr-xr-x 25 zkim staff 850 Jul 5 13:02 .. 47 | drwxr-xr-x 12 zkim staff 408 Jul 5 13:02 .git 48 | -rw-r--r-- 1 zkim staff 13 Jul 5 13:02 .gitignore 49 | -rw-r--r-- 1 zkim staff 12638 Jul 5 13:02 LICENSE.html 50 | -rw-r--r-- 1 zkim staff 4092 Jul 5 13:02 README.md 51 | drwxr-xr-x 2 zkim staff 68 Jul 5 13:15 classes 52 | drwxr-xr-x 5 zkim staff 170 Jul 5 13:15 lib 53 | -rw-r--r--@ 1 zkim staff 3396 Jul 5 13:03 pom.xml 54 | -rw-r--r--@ 1 zkim staff 367 Jul 5 13:15 project.clj 55 | drwxr-xr-x 4 zkim staff 136 Jul 5 13:15 src 56 | ", :err ""} 57 | 58 | 59 | user=> (use '[clojure.java.shell :only [sh]]) 60 | 61 | user=> (println (:out (sh "cowsay" "Printing a command-line output"))) 62 | 63 | _________________________________ 64 | < Printing a command-line output. > 65 | --------------------------------- 66 | \ ^__^ 67 | \ (oo)\_______ 68 | (__)\ )\/\ 69 | ||----w | 70 | || || 71 | 72 | nil 73 | 74 | 75 | 76 | 77 | user=> (use '[clojure.java.shell :only [sh]]) 78 | nil 79 | 80 | ;; note that the options, like :in, have to go at the end of arglist 81 | ;; advantage of piping-in thru stdin is less need for quoting/escaping 82 | user=> (println (:out (sh "cat" "-" :in "Printing input from stdin with funny chars like ' \" $@ & "))) 83 | Printing input from stdin with funny chars like ' " $@ & 84 | nil 85 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\ClojureAPI.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\ClojureAPI.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 18 | 19 | help: 20 | @echo "Please use \`make ' where is one of" 21 | @echo " html to make standalone HTML files" 22 | @echo " dirhtml to make HTML files named index.html in directories" 23 | @echo " singlehtml to make a single large HTML file" 24 | @echo " pickle to make pickle files" 25 | @echo " json to make JSON files" 26 | @echo " htmlhelp to make HTML files and a HTML help project" 27 | @echo " qthelp to make HTML files and a qthelp project" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 31 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 32 | @echo " text to make text files" 33 | @echo " man to make manual pages" 34 | @echo " texinfo to make Texinfo files" 35 | @echo " info to make Texinfo files and run them through makeinfo" 36 | @echo " gettext to make PO message catalogs" 37 | @echo " changes to make an overview of all changed/added/deprecated items" 38 | @echo " linkcheck to check all external links for integrity" 39 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 40 | 41 | clean: 42 | -rm -rf $(BUILDDIR)/* 43 | 44 | html: 45 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 46 | @echo 47 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 48 | 49 | dirhtml: 50 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 51 | @echo 52 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 53 | 54 | singlehtml: 55 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 56 | @echo 57 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 58 | 59 | pickle: 60 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 61 | @echo 62 | @echo "Build finished; now you can process the pickle files." 63 | 64 | json: 65 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 66 | @echo 67 | @echo "Build finished; now you can process the JSON files." 68 | 69 | htmlhelp: 70 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 71 | @echo 72 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 73 | ".hhp project file in $(BUILDDIR)/htmlhelp." 74 | 75 | qthelp: 76 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 77 | @echo 78 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 79 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 80 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ClojureAPI.qhcp" 81 | @echo "To view the help file:" 82 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ClojureAPI.qhc" 83 | 84 | devhelp: 85 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 86 | @echo 87 | @echo "Build finished." 88 | @echo "To view the help file:" 89 | @echo "# mkdir -p $$HOME/.local/share/devhelp/ClojureAPI" 90 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ClojureAPI" 91 | @echo "# devhelp" 92 | 93 | epub: 94 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 95 | @echo 96 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 97 | 98 | latex: 99 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 100 | @echo 101 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 102 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 103 | "(use \`make latexpdf' here to do that automatically)." 104 | 105 | latexpdf: 106 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 107 | @echo "Running LaTeX files through pdflatex..." 108 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 109 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 110 | 111 | text: 112 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 113 | @echo 114 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 115 | 116 | man: 117 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 118 | @echo 119 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 120 | 121 | texinfo: 122 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 123 | @echo 124 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 125 | @echo "Run \`make' in that directory to run these through makeinfo" \ 126 | "(use \`make info' here to do that automatically)." 127 | 128 | info: 129 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 130 | @echo "Running Texinfo files through makeinfo..." 131 | make -C $(BUILDDIR)/texinfo info 132 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 133 | 134 | gettext: 135 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 136 | @echo 137 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 138 | 139 | changes: 140 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 141 | @echo 142 | @echo "The overview file is in $(BUILDDIR)/changes." 143 | 144 | linkcheck: 145 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 146 | @echo 147 | @echo "Link check complete; look for any errors in the above output " \ 148 | "or in $(BUILDDIR)/linkcheck/output.txt." 149 | 150 | doctest: 151 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 152 | @echo "Testing of doctests in the sources finished, look at the " \ 153 | "results in $(BUILDDIR)/doctest/output.txt." 154 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/epub.css: -------------------------------------------------------------------------------- 1 | /* 2 | * default.css_t 3 | * ~~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- default theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: {{ theme_bodyfont }}; 18 | font-size: 100%; 19 | background-color: {{ theme_footerbgcolor }}; 20 | color: #000; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.document { 26 | background-color: {{ theme_sidebarbgcolor }}; 27 | } 28 | 29 | div.documentwrapper { 30 | float: left; 31 | width: 100%; 32 | } 33 | 34 | div.bodywrapper { 35 | margin: 0 0 0 230px; 36 | } 37 | 38 | div.body { 39 | background-color: {{ theme_bgcolor }}; 40 | color: {{ theme_textcolor }}; 41 | padding: 0 20px 30px 20px; 42 | } 43 | 44 | {%- if theme_rightsidebar|tobool %} 45 | div.bodywrapper { 46 | margin: 0 230px 0 0; 47 | } 48 | {%- endif %} 49 | 50 | div.footer { 51 | color: {{ theme_footertextcolor }}; 52 | width: 100%; 53 | padding: 9px 0 9px 0; 54 | text-align: center; 55 | font-size: 75%; 56 | } 57 | 58 | div.footer a { 59 | color: {{ theme_footertextcolor }}; 60 | text-decoration: underline; 61 | } 62 | 63 | div.related { 64 | background-color: {{ theme_relbarbgcolor }}; 65 | line-height: 30px; 66 | color: {{ theme_relbartextcolor }}; 67 | } 68 | 69 | div.related a { 70 | color: {{ theme_relbarlinkcolor }}; 71 | } 72 | 73 | div.sphinxsidebar { 74 | {%- if theme_stickysidebar|tobool %} 75 | top: 30px; 76 | bottom: 0; 77 | margin: 0; 78 | position: fixed; 79 | overflow: auto; 80 | height: auto; 81 | {%- endif %} 82 | {%- if theme_rightsidebar|tobool %} 83 | float: right; 84 | {%- if theme_stickysidebar|tobool %} 85 | right: 0; 86 | {%- endif %} 87 | {%- endif %} 88 | } 89 | 90 | {%- if theme_stickysidebar|tobool %} 91 | /* this is nice, but it it leads to hidden headings when jumping 92 | to an anchor */ 93 | /* 94 | div.related { 95 | position: fixed; 96 | } 97 | 98 | div.documentwrapper { 99 | margin-top: 30px; 100 | } 101 | */ 102 | {%- endif %} 103 | 104 | div.sphinxsidebar h3 { 105 | font-family: {{ theme_headfont }}; 106 | color: {{ theme_sidebartextcolor }}; 107 | font-size: 1.4em; 108 | font-weight: normal; 109 | margin: 0; 110 | padding: 0; 111 | } 112 | 113 | div.sphinxsidebar h3 a { 114 | color: {{ theme_sidebartextcolor }}; 115 | } 116 | 117 | div.sphinxsidebar h4 { 118 | font-family: {{ theme_headfont }}; 119 | color: {{ theme_sidebartextcolor }}; 120 | font-size: 1.3em; 121 | font-weight: normal; 122 | margin: 5px 0 0 0; 123 | padding: 0; 124 | } 125 | 126 | div.sphinxsidebar p { 127 | color: {{ theme_sidebartextcolor }}; 128 | } 129 | 130 | div.sphinxsidebar p.topless { 131 | margin: 5px 10px 10px 10px; 132 | } 133 | 134 | div.sphinxsidebar ul { 135 | margin: 10px; 136 | padding: 0; 137 | color: {{ theme_sidebartextcolor }}; 138 | } 139 | 140 | div.sphinxsidebar a { 141 | color: {{ theme_sidebarlinkcolor }}; 142 | } 143 | 144 | div.sphinxsidebar input { 145 | border: 1px solid {{ theme_sidebarlinkcolor }}; 146 | font-family: sans-serif; 147 | font-size: 1em; 148 | } 149 | 150 | {% if theme_collapsiblesidebar|tobool %} 151 | /* for collapsible sidebar */ 152 | div#sidebarbutton { 153 | background-color: {{ theme_sidebarbtncolor }}; 154 | } 155 | {% endif %} 156 | 157 | /* -- hyperlink styles ------------------------------------------------------ */ 158 | 159 | a { 160 | color: {{ theme_linkcolor }}; 161 | text-decoration: none; 162 | } 163 | 164 | a:visited { 165 | color: {{ theme_visitedlinkcolor }}; 166 | text-decoration: none; 167 | } 168 | 169 | a:hover { 170 | text-decoration: underline; 171 | } 172 | 173 | {% if theme_externalrefs|tobool %} 174 | a.external { 175 | text-decoration: none; 176 | border-bottom: 1px dashed {{ theme_linkcolor }}; 177 | } 178 | 179 | a.external:hover { 180 | text-decoration: none; 181 | border-bottom: none; 182 | } 183 | 184 | a.external:visited { 185 | text-decoration: none; 186 | border-bottom: 1px dashed {{ theme_visitedlinkcolor }}; 187 | } 188 | {% endif %} 189 | 190 | /* -- body styles ----------------------------------------------------------- */ 191 | 192 | div.body h1, 193 | div.body h2, 194 | div.body h3, 195 | div.body h4, 196 | div.body h5, 197 | div.body h6 { 198 | font-family: {{ theme_headfont }}; 199 | background-color: {{ theme_headbgcolor }}; 200 | font-weight: normal; 201 | color: {{ theme_headtextcolor }}; 202 | border-bottom: 1px solid #ccc; 203 | margin: 20px -20px 10px -20px; 204 | padding: 3px 0 3px 10px; 205 | } 206 | 207 | div.body h1 { margin-top: 0; font-size: 200%; } 208 | div.body h2 { font-size: 160%; } 209 | div.body h3 { font-size: 140%; } 210 | div.body h4 { font-size: 120%; } 211 | div.body h5 { font-size: 110%; } 212 | div.body h6 { font-size: 100%; } 213 | 214 | a.headerlink { 215 | color: {{ theme_headlinkcolor }}; 216 | font-size: 0.8em; 217 | padding: 0 4px 0 4px; 218 | text-decoration: none; 219 | } 220 | 221 | a.headerlink:hover { 222 | background-color: {{ theme_headlinkcolor }}; 223 | color: white; 224 | } 225 | 226 | div.body p, div.body dd, div.body li { 227 | text-align: justify; 228 | line-height: 130%; 229 | } 230 | 231 | div.admonition p.admonition-title + p { 232 | display: inline; 233 | } 234 | 235 | div.admonition p { 236 | margin-bottom: 5px; 237 | } 238 | 239 | div.admonition pre { 240 | margin-bottom: 5px; 241 | } 242 | 243 | div.admonition ul, div.admonition ol { 244 | margin-bottom: 5px; 245 | } 246 | 247 | div.note { 248 | background-color: #eee; 249 | border: 1px solid #ccc; 250 | } 251 | 252 | div.seealso { 253 | background-color: #ffc; 254 | border: 1px solid #ff6; 255 | } 256 | 257 | div.topic { 258 | background-color: #eee; 259 | } 260 | 261 | div.warning { 262 | background-color: #ffe4e4; 263 | border: 1px solid #f66; 264 | } 265 | 266 | p.admonition-title { 267 | display: inline; 268 | } 269 | 270 | p.admonition-title:after { 271 | content: ":"; 272 | } 273 | 274 | pre { 275 | padding: 5px; 276 | background-color: {{ theme_codebgcolor }}; 277 | color: {{ theme_codetextcolor }}; 278 | line-height: 120%; 279 | border: 1px solid #ac9; 280 | border-left: none; 281 | border-right: none; 282 | } 283 | 284 | tt { 285 | background-color: #ecf0f3; 286 | padding: 0 1px 0 1px; 287 | font-size: 0.95em; 288 | } 289 | 290 | th { 291 | background-color: #ede; 292 | } 293 | 294 | .warning tt { 295 | background: #efc2c2; 296 | } 297 | 298 | .note tt { 299 | background: #d6d6d6; 300 | } 301 | 302 | .viewcode-back { 303 | font-family: {{ theme_bodyfont }}; 304 | } 305 | 306 | div.viewcode-block:target { 307 | background-color: #f4debf; 308 | border-top: 1px solid #ac9; 309 | border-bottom: 1px solid #ac9; 310 | } 311 | -------------------------------------------------------------------------------- /fixed_width_pyramid/static/pyramid.css_t: -------------------------------------------------------------------------------- 1 | /* 2 | * pyramid.css_t 3 | * ~~~~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- pylons theme. 6 | * 7 | * :copyright: Copyright 2007-2010 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | @import url("basic.css"); 13 | 14 | /* -- page layout ----------------------------------------------------------- */ 15 | 16 | body { 17 | font-family: "Nobile", sans-serif; 18 | font-size: 100%; 19 | background-color: #393939; 20 | color: #ffffff; 21 | margin: 0; 22 | padding: 0; 23 | } 24 | 25 | div.documentwrapper { 26 | float: left; 27 | width: 100%; 28 | } 29 | 30 | div.bodywrapper { 31 | margin: 0 0 0 {{ theme_sidebarwidth }}px; 32 | } 33 | 34 | hr { 35 | border: 1px solid #B1B4B6; 36 | } 37 | 38 | div.document { 39 | background-color: #eee; 40 | } 41 | 42 | div.header { 43 | width:100%; 44 | background: #f4ad32 url(headerbg.png) repeat-x 0 top; 45 | border-bottom: 2px solid #ffffff; 46 | } 47 | 48 | div.logo { 49 | text-align: center; 50 | padding-top: 10px; 51 | } 52 | 53 | div.body { 54 | width: 900px; 55 | background-color: #ffffff; 56 | color: #3E4349; 57 | padding: 0 30px 30px 30px; 58 | font-size: 1em; 59 | border: 2px solid #ddd; 60 | overflow: auto; 61 | } 62 | 63 | div.footer { 64 | color: #ffffff; 65 | width: 100%; 66 | padding: 13px 0; 67 | text-align: center; 68 | font-size: 75%; 69 | background: transparent; 70 | clear:both; 71 | } 72 | 73 | div.footer a { 74 | color: #ffffff; 75 | text-decoration: none; 76 | } 77 | 78 | div.footer a:hover { 79 | color: #e88f00; 80 | text-decoration: underline; 81 | } 82 | 83 | div.related { 84 | line-height: 30px; 85 | color: #373839; 86 | font-size: 0.8em; 87 | background-color: #eee; 88 | } 89 | 90 | div.related a { 91 | color: #1b61d6; 92 | } 93 | 94 | div.related ul { 95 | width: 960px; 96 | padding-left: {{ theme_sidebarwidth|toint + 10 }}px; 97 | } 98 | 99 | div.sphinxsidebar { 100 | font-size: 0.75em; 101 | line-height: 1.5em; 102 | } 103 | 104 | div.sphinxsidebarwrapper{ 105 | padding: 10px 0; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: "Neuton", sans-serif; 111 | color: #373839; 112 | font-size: 1.4em; 113 | font-weight: normal; 114 | margin: 0; 115 | padding: 5px 10px; 116 | border-bottom: 2px solid #ddd; 117 | } 118 | 119 | div.sphinxsidebar h4{ 120 | font-size: 1.3em; 121 | } 122 | 123 | div.sphinxsidebar h3 a { 124 | color: #000000; 125 | } 126 | 127 | 128 | div.sphinxsidebar p { 129 | color: #888; 130 | padding: 5px 20px; 131 | } 132 | 133 | div.sphinxsidebar p.topless { 134 | } 135 | 136 | div.sphinxsidebar ul { 137 | margin: 10px 20px; 138 | padding: 0; 139 | color: #373839; 140 | } 141 | 142 | div.sphinxsidebar a { 143 | color: #444; 144 | } 145 | 146 | div.sphinxsidebar input { 147 | border: 1px solid #ccc; 148 | font-family: sans-serif; 149 | font-size: 1em; 150 | } 151 | 152 | div.sphinxsidebar input[type=text]{ 153 | margin-left: 20px; 154 | } 155 | 156 | /* -- sidebars -------------------------------------------------------------- */ 157 | 158 | div.sidebar { 159 | margin: 0 0 0.5em 1em; 160 | border: 2px solid #c6d880; 161 | background-color: #e6efc2; 162 | width: 40%; 163 | float: right; 164 | border-right-style: none; 165 | border-left-style: none; 166 | padding: 10px 20px; 167 | } 168 | 169 | p.sidebar-title { 170 | font-weight: bold; 171 | } 172 | 173 | /* -- body styles ----------------------------------------------------------- */ 174 | 175 | a, a .pre { 176 | color: #1b61d6; 177 | text-decoration: none; 178 | } 179 | 180 | a:hover, a:hover .pre { 181 | text-decoration: underline; 182 | } 183 | 184 | div.body h1, 185 | div.body h2, 186 | div.body h3, 187 | div.body h4, 188 | div.body h5, 189 | div.body h6 { 190 | font-family: "Neuton", sans-serif; 191 | background-color: #ffffff; 192 | font-weight: normal; 193 | color: #373839; 194 | margin: 30px 0px 10px 0px; 195 | padding: 5px 0; 196 | } 197 | 198 | div.body h1 { border-top: 20px solid white; margin-top: 0; font-size: 200%; } 199 | div.body h2 { font-size: 150%; background-color: #ffffff; } 200 | div.body h3 { font-size: 120%; background-color: #ffffff; } 201 | div.body h4 { font-size: 110%; background-color: #ffffff; } 202 | div.body h5 { font-size: 100%; background-color: #ffffff; } 203 | div.body h6 { font-size: 100%; background-color: #ffffff; } 204 | 205 | a.headerlink { 206 | color: #1b61d6; 207 | font-size: 0.8em; 208 | padding: 0 4px 0 4px; 209 | text-decoration: none; 210 | } 211 | 212 | a.headerlink:hover { 213 | text-decoration: underline; 214 | } 215 | 216 | div.body p, div.body dd, div.body li { 217 | line-height: 1.5em; 218 | } 219 | 220 | div.admonition p.admonition-title + p { 221 | display: inline; 222 | } 223 | 224 | div.admonition { 225 | background: #eeeeec; 226 | border: 2px solid #babdb6; 227 | border-right-style: none; 228 | border-left-style: none; 229 | padding: 10px 20px 10px 60px; 230 | } 231 | 232 | div.highlight{ 233 | background-color: white; 234 | } 235 | 236 | div.note { 237 | border: 2px solid #7a9eec; 238 | border-right-style: none; 239 | border-left-style: none; 240 | padding: 10px 20px 10px 60px; 241 | background: #e1ecfe url(dialog-note.png) no-repeat 10px 8px; 242 | } 243 | 244 | div.seealso { 245 | background: #fff6bf url(dialog-seealso.png) no-repeat 10px 8px; 246 | border: 2px solid #ffd324; 247 | border-left-style: none; 248 | border-right-style: none; 249 | padding: 10px 20px 10px 60px; 250 | } 251 | 252 | div.topic { 253 | background: #eeeeee; 254 | border: 2px solid #C6C9CB; 255 | padding: 10px 20px; 256 | border-right-style: none; 257 | border-left-style: none; 258 | } 259 | 260 | div.warning { 261 | background: #fbe3e4 url(dialog-warning.png) no-repeat 10px 8px; 262 | border: 2px solid #fbc2c4; 263 | border-right-style: none; 264 | border-left-style: none; 265 | padding: 10px 20px 10px 60px; 266 | } 267 | 268 | div.admonition-todo { 269 | background: #f2d9b4 url(dialog-todo.png) no-repeat 10px 8px; 270 | border: 2px solid #e9b96e; 271 | border-right-style: none; 272 | border-left-style: none; 273 | padding: 10px 20px 10px 60px; 274 | } 275 | 276 | div.note p.admonition-title, 277 | div.warning p.admonition-title, 278 | div.seealso p.admonition-title, 279 | div.admonition-todo p.admonition-title { 280 | display: none; 281 | } 282 | 283 | p.admonition-title:after { 284 | content: ":"; 285 | } 286 | 287 | pre { 288 | padding: 10px; 289 | background-color: #fafafa; 290 | color: #222; 291 | line-height: 1.2em; 292 | border: 2px solid #C6C9CB; 293 | font-size: 1.1em; 294 | margin: 1.5em 0 1.5em 0; 295 | border-right-style: none; 296 | border-left-style: none; 297 | } 298 | 299 | tt { 300 | background-color: transparent; 301 | color: #222; 302 | font-size: 1.1em; 303 | font-family: monospace; 304 | } 305 | 306 | .viewcode-back { 307 | font-family: "Nobile", sans-serif; 308 | } 309 | 310 | div.viewcode-block:target { 311 | background-color: #fff6bf; 312 | border: 2px solid #ffd324; 313 | border-left-style: none; 314 | border-right-style: none; 315 | padding: 10px 20px; 316 | } 317 | 318 | table.highlighttable { 319 | width: 100%; 320 | } 321 | 322 | table.highlighttable td { 323 | padding: 0; 324 | } 325 | 326 | a em.std-term { 327 | color: #007f00; 328 | } 329 | 330 | a:hover em.std-term { 331 | text-decoration: underline; 332 | } 333 | 334 | .download { 335 | font-family: "Nobile", sans-serif; 336 | font-weight: normal; 337 | font-style: normal; 338 | } 339 | 340 | tt.xref { 341 | font-weight: normal; 342 | font-style: normal; 343 | } 344 | -------------------------------------------------------------------------------- /fixed_width_pyramid/layout.html: -------------------------------------------------------------------------------- 1 | {# 2 | basic/layout.html 3 | ~~~~~~~~~~~~~~~~~ 4 | 5 | Master layout template for Sphinx themes. 6 | 7 | :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS. 8 | :license: BSD, see LICENSE for details. 9 | #} 10 | 11 | {%- block doctype -%} 12 | 14 | {%- endblock %} 15 | 16 | {%- set reldelim1 = reldelim1 is not defined and ' »' or reldelim1 %} 17 | {%- set reldelim2 = reldelim2 is not defined and ' |' or reldelim2 %} 18 | {%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and 19 | (sidebars != []) %} 20 | {%- set url_root = pathto('', 1) %} 21 | {# XXX necessary? #} 22 | {%- if url_root == '#' %}{% set url_root = '' %}{% endif %} 23 | {%- if not embedded and docstitle %} 24 | {%- set titlesuffix = " — "|safe + docstitle|e %} 25 | {%- else %} 26 | {%- set titlesuffix = "" %} 27 | {%- endif %} 28 | 29 | {%- macro relbar() %} 30 | 48 | {%- endmacro %} 49 | 50 | {%- macro sidebar() %} 51 | {%- if render_sidebar %} 52 |
53 |
54 | {%- block sidebarlogo %} 55 | {%- if logo %} 56 | 59 | {%- endif %} 60 | {%- endblock %} 61 | {%- if sidebars != None %} 62 | {#- new style sidebar: explicitly include/exclude templates #} 63 | {%- for sidebartemplate in sidebars %} 64 | {%- include sidebartemplate %} 65 | {%- endfor %} 66 | {%- else %} 67 | {#- old style sidebars: using blocks -- should be deprecated #} 68 | {%- block sidebartoc %} 69 | {%- include "localtoc.html" %} 70 | {%- endblock %} 71 | {%- block sidebarrel %} 72 | {%- include "relations.html" %} 73 | {%- endblock %} 74 | {%- if customsidebar %} 75 | {%- include customsidebar %} 76 | {%- endif %} 77 | {%- block sidebarsearch %} 78 | {%- include "searchbox.html" %} 79 | {%- endblock %} 80 | {%- endif %} 81 | {%- endif %} 82 |
83 |
84 | {%- endmacro %} 85 | 86 | {%- macro script() %} 87 | 96 | {%- for scriptfile in script_files %} 97 | 98 | {%- endfor %} 99 | {%- endmacro %} 100 | 101 | {%- macro css() %} 102 | 103 | 104 | {%- for cssfile in css_files %} 105 | 106 | {%- endfor %} 107 | {%- endmacro %} 108 | 109 | 110 | 111 | 112 | {{ metatags }} 113 | {%- block htmltitle %} 114 | {{ title|striptags|e }}{{ titlesuffix }} 115 | {%- endblock %} 116 | {{ css() }} 117 | {%- if not embedded %} 118 | {{ script() }} 119 | {%- if use_opensearch %} 120 | 123 | {%- endif %} 124 | {%- if favicon %} 125 | 126 | {%- endif %} 127 | {%- endif %} 128 | {%- block linktags %} 129 | {%- if hasdoc('about') %} 130 | 131 | {%- endif %} 132 | {%- if hasdoc('genindex') %} 133 | 134 | {%- endif %} 135 | {%- if hasdoc('search') %} 136 | 137 | {%- endif %} 138 | {%- if hasdoc('copyright') %} 139 | 140 | {%- endif %} 141 | 142 | {%- if parents %} 143 | 144 | {%- endif %} 145 | {%- if next %} 146 | 147 | {%- endif %} 148 | {%- if prev %} 149 | 150 | {%- endif %} 151 | {%- endblock %} 152 | 153 | {%- block extrahead %} 154 | 157 | {% endblock %} 158 | 159 | {% block header %} 160 | {%- if logo %} 161 |
162 | 167 |
168 | {%- endif %} 169 | {% endblock %} 170 | 171 | 172 | 173 | {%- block relbar1 %}{{ relbar() }}{% endblock %} 174 | 175 | {%- block relbar2 %}{% endblock %} 176 | 177 | {%- block content %} 178 | {%- block sidebar1 %} {# possible location for sidebar #} {% endblock %} 179 | 180 |
181 | {%- block document %} 182 |
183 | {%- if render_sidebar %} 184 |
185 | {%- endif %} 186 |
187 | {% block body %} {% endblock %} 188 | 189 | {% include "disqus.html" %} 190 | 191 |
192 | {%- if render_sidebar %} 193 |
194 | {%- endif %} 195 |
196 | {%- endblock %} 197 | 198 | {%- block sidebar2 %}{{ sidebar() }}{% endblock %} 199 |
200 |
201 | {%- endblock %} 202 | 203 | 204 | 205 | {%- block footer %} 206 | 221 | {%- endblock %} 222 | 223 | 224 | -------------------------------------------------------------------------------- /conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Clojure API 文档 documentation build configuration file, created by 4 | # sphinx-quickstart on Sun Jun 17 19:46:43 2012. 5 | # 6 | # This file is execfile()d with the current directory set to its containing dir. 7 | # 8 | # Note that not all possible configuration values are present in this 9 | # autogenerated file. 10 | # 11 | # All configuration values have a default; values that are commented out 12 | # serve to show the default. 13 | 14 | import sys, os 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | #sys.path.insert(0, os.path.abspath('.')) 20 | 21 | # -- General configuration ----------------------------------------------------- 22 | 23 | # If your documentation needs a minimal Sphinx version, state it here. 24 | #needs_sphinx = '1.0' 25 | 26 | # Add any Sphinx extension module names here, as strings. They can be extensions 27 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 28 | extensions = [] 29 | 30 | # Add any paths that contain templates here, relative to this directory. 31 | templates_path = ['_templates'] 32 | 33 | # The suffix of source filenames. 34 | source_suffix = '.rst' 35 | 36 | # The encoding of source files. 37 | #source_encoding = 'utf-8-sig' 38 | 39 | # The master toctree document. 40 | master_doc = 'index' 41 | 42 | # General information about the project. 43 | project = u'Clojure API 文档' 44 | copyright = u'2007-2012 by Rich Hickey' 45 | 46 | # The version info for the project you're documenting, acts as replacement for 47 | # |version| and |release|, also used in various other places throughout the 48 | # built documents. 49 | # 50 | # The short X.Y version. 51 | version = '1.4' 52 | # The full version, including alpha/beta/rc tags. 53 | release = '1.4' 54 | 55 | # The language for content autogenerated by Sphinx. Refer to documentation 56 | # for a list of supported languages. 57 | language = u'zh_CN' 58 | 59 | # There are two options for replacing |today|: either, you set today to some 60 | # non-false value, then it is used: 61 | #today = '' 62 | # Else, today_fmt is used as the format for a strftime call. 63 | #today_fmt = '%B %d, %Y' 64 | 65 | # List of patterns, relative to source directory, that match files and 66 | # directories to ignore when looking for source files. 67 | exclude_patterns = ['_build'] 68 | 69 | # The reST default role (used for this markup: `text`) to use for all documents. 70 | #default_role = None 71 | 72 | # If true, '()' will be appended to :func: etc. cross-reference text. 73 | #add_function_parentheses = True 74 | 75 | # If true, the current module name will be prepended to all description 76 | # unit titles (such as .. function::). 77 | #add_module_names = True 78 | 79 | # If true, sectionauthor and moduleauthor directives will be shown in the 80 | # output. They are ignored by default. 81 | #show_authors = False 82 | 83 | # The name of the Pygments (syntax highlighting) style to use. 84 | pygments_style = 'sphinx' 85 | 86 | # A list of ignored prefixes for module index sorting. 87 | #modindex_common_prefix = [] 88 | 89 | 90 | # -- Options for HTML output --------------------------------------------------- 91 | 92 | # The theme to use for HTML and HTML Help pages. See the documentation for 93 | # a list of builtin themes. 94 | html_theme = 'fixed_width_pyramid' 95 | 96 | # Theme options are theme-specific and customize the look and feel of a theme 97 | # further. For a list of options available for each theme, see the 98 | # documentation. 99 | #html_theme_options = {} 100 | 101 | # Add any paths that contain custom themes here, relative to this directory. 102 | html_theme_path = ["."] 103 | 104 | # The name for this set of Sphinx documents. If None, it defaults to 105 | # " v documentation". 106 | html_title = u'Clojure API 文档' 107 | 108 | # A shorter title for the navigation bar. Default is the same as html_title. 109 | #html_short_title = None 110 | 111 | # The name of an image file (relative to this directory) to place at the top 112 | # of the sidebar. 113 | #html_logo = None 114 | 115 | # The name of an image file (within the static path) to use as favicon of the 116 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 117 | # pixels large. 118 | #html_favicon = None 119 | 120 | # Add any paths that contain custom static files (such as style sheets) here, 121 | # relative to this directory. They are copied after the builtin static files, 122 | # so a file named "default.css" will overwrite the builtin "default.css". 123 | html_static_path = ['_static'] 124 | 125 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, 126 | # using the given strftime format. 127 | #html_last_updated_fmt = '%b %d, %Y' 128 | 129 | # If true, SmartyPants will be used to convert quotes and dashes to 130 | # typographically correct entities. 131 | #html_use_smartypants = True 132 | 133 | # Custom sidebar templates, maps document names to template names. 134 | #html_sidebars = {} 135 | 136 | # Additional templates that should be rendered to pages, maps page names to 137 | # template names. 138 | #html_additional_pages = {} 139 | 140 | # If false, no module index is generated. 141 | #html_domain_indices = True 142 | 143 | # If false, no index is generated. 144 | #html_use_index = True 145 | 146 | # If true, the index is split into individual pages for each letter. 147 | #html_split_index = False 148 | 149 | # If true, links to the reST sources are added to the pages. 150 | #html_show_sourcelink = True 151 | 152 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 153 | #html_show_sphinx = True 154 | 155 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 156 | #html_show_copyright = True 157 | 158 | # If true, an OpenSearch description file will be output, and all pages will 159 | # contain a tag referring to it. The value of this option must be the 160 | # base URL from which the finished HTML is served. 161 | #html_use_opensearch = '' 162 | 163 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 164 | #html_file_suffix = None 165 | 166 | # Output file base name for HTML help builder. 167 | htmlhelp_basename = 'ClojureAPIdoc' 168 | 169 | 170 | # -- Options for LaTeX output -------------------------------------------------- 171 | 172 | latex_elements = { 173 | # The paper size ('letterpaper' or 'a4paper'). 174 | #'papersize': 'letterpaper', 175 | 176 | # The font size ('10pt', '11pt' or '12pt'). 177 | #'pointsize': '10pt', 178 | 179 | # Additional stuff for the LaTeX preamble. 180 | #'preamble': '', 181 | } 182 | 183 | # Grouping the document tree into LaTeX files. List of tuples 184 | # (source start file, target name, title, author, documentclass [howto/manual]). 185 | latex_documents = [ 186 | ('index', 'ClojureAPI.tex', u'Clojure API 文档 Documentation', 187 | u'huangz1990', 'manual'), 188 | ] 189 | 190 | # The name of an image file (relative to this directory) to place at the top of 191 | # the title page. 192 | #latex_logo = None 193 | 194 | # For "manual" documents, if this is true, then toplevel headings are parts, 195 | # not chapters. 196 | #latex_use_parts = False 197 | 198 | # If true, show page references after internal links. 199 | #latex_show_pagerefs = False 200 | 201 | # If true, show URL addresses after external links. 202 | #latex_show_urls = False 203 | 204 | # Documents to append as an appendix to all manuals. 205 | #latex_appendices = [] 206 | 207 | # If false, no module index is generated. 208 | #latex_domain_indices = True 209 | 210 | 211 | # -- Options for manual page output -------------------------------------------- 212 | 213 | # One entry per manual page. List of tuples 214 | # (source start file, name, description, authors, manual section). 215 | man_pages = [ 216 | ('index', 'clojureapi', u'Clojure API 文档 Documentation', 217 | [u'huangz1990'], 1) 218 | ] 219 | 220 | # If true, show URL addresses after external links. 221 | #man_show_urls = False 222 | 223 | 224 | # -- Options for Texinfo output ------------------------------------------------ 225 | 226 | # Grouping the document tree into Texinfo files. List of tuples 227 | # (source start file, target name, title, author, 228 | # dir menu entry, description, category) 229 | texinfo_documents = [ 230 | ('index', 'ClojureAPI', u'Clojure API 文档 Documentation', 231 | u'huangz1990', 'ClojureAPI', 'One line description of project.', 232 | 'Miscellaneous'), 233 | ] 234 | 235 | # Documents to append as an appendix to all manuals. 236 | #texinfo_appendices = [] 237 | 238 | # If false, no module index is generated. 239 | #texinfo_domain_indices = True 240 | 241 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 242 | #texinfo_show_urls = 'footnote' 243 | 244 | highlight_language = 'clojure' 245 | --------------------------------------------------------------------------------