非常感謝 Steve Tayon 撰寫此手冊,以及 Andy Fingerhut 持續維護。
文字 | Long:7,十六進制 0xff,八進制 017,二進制 2r1011,三十六進制 36rCRAZY BigInt:7N Ratio:-22/7 Double:2.78 -1.2e-5 BigDecimal:4.2M |
算術 | + - * / quot rem mod inc dec max min +' -' *' inc' dec' (1.11) abs |
比較 | == < > <= >= compare |
位元 | bit-and bit-or bit-xor bit-not bit-flip bit-set bit-shift-right bit-shift-left bit-and-not bit-clear bit-test unsigned-bit-shift-right (請參閱 BigInteger,以取得比 Long 還要大的整數) |
轉型 | byte short int long float double bigdec bigint num rationalize biginteger |
測試 | zero? pos? neg? even? odd? number? rational? integer? ratio? decimal? float? (1.9) double? int? nat-int? neg-int? pos-int? (1.11) NaN? infinite? |
隨機 | rand rand-int |
BigDecimal | with-precision |
Unchecked | *unchecked-math* unchecked-add unchecked-dec unchecked-inc unchecked-multiply unchecked-negate unchecked-subtract |
建立 | str format "a string" "escapes \b\f\n\t\r\" octal \377 hex \ucafe" 另請參閱 IO/to string 區段 |
使用 | count get subs compare (clojure.string/) join escape split split-lines replace replace-first reverse index-of last-index-of (1.11) (clojure.core/) parse-boolean parse-double parse-long parse-uuid |
Regex | #"pattern" re-find re-seq re-matches re-pattern re-matcher re-groups (clojure.string/) replace replace-first re-quote-replacement Note: \ in |
字母 | (clojure.string/) capitalize lower-case upper-case |
修剪 | (clojure.string/) trim trim-newline triml trimr |
測試 | string? (clojure.string/) blank? starts-with? ends-with? includes? |
字元 | char char? char-name-string char-escape-string 文字: \a \newline(更多資訊請參閱連結) |
關鍵字 | keyword keyword? find-keyword 文字: :kw :my.name.space/kw ::in-cur-namespace ::namespace-alias/kw |
符號 | symbol symbol? gensym 文字: my-sym my.ns/foo |
雜項 | 文字: true false nil |
一般操作 | count empty not-empty into conj (clojure.walk/) walk prewalk prewalk-demo prewalk-replace postwalk postwalk-demo postwalk-replace (1.9) bounded-count |
內容測試 | distinct? empty? every? not-every? some not-any? |
功能 | sequential? associative? sorted? counted? reversible? |
類型測試 | coll? list? vector? set? map? seq? record? map-entry? |
建立 | () list list* |
檢查 | first nth peek .indexOf .lastIndexOf |
「變更」 | cons conj rest pop |
建立 | [] vector vec vector-of mapv filterv |
檢查 |
|
「變更」 | assoc assoc-in pop subvec replace conj rseq update update-in |
運算 | reduce-kv |
建立未排序集合 | #{} set hash-set |
建立已排序集合 | sorted-set sorted-set-by (clojure.data.avl/) sorted-set sorted-set-by (flatland.ordered.set/) ordered-set (clojure.data.int-map/) int-set dense-int-set |
檢查 |
|
「變更」 | conj disj |
集合運算 | (clojure.set/) union difference intersection select 另請參閱關係部分 |
測試 | (clojure.set/) subset? superset? |
已排序集合 | rseq subseq rsubseq |
建立未排序集合 | {} hash-map array-map zipmap bean frequencies group-by (clojure.set/) index |
建立已排序集合 | sorted-map sorted-map-by (clojure.data.avl/) sorted-map sorted-map-by (flatland.ordered.map/) ordered-map (clojure.data.priority-map/) priority-map (flatland.useful.map/) ordering-map (clojure.data.int-map/) int-map |
檢查 |
|
「變更」 | assoc assoc-in dissoc merge merge-with select-keys update update-in (clojure.set/) rename-keys map-invert (1.11) (clojure.core/) update-keys update-vals GitHub: Medley |
運算 | reduce-kv |
項目 | key val |
已排序的映射 | rseq subseq rsubseq |
建立 | clojure.lang.PersistentQueue/EMPTY(沒有文字語法或建構函數 fn) |
檢查 | 窺視 |
「變更」 | conj pop |
關係代數 | (clojure.set/) join select project union difference intersection index rename |
建立 | transient persistent! |
變更 | conj! pop! assoc! dissoc! disj! 注意:永遠使用回傳值進行後續的變更,切勿使用原始值! |
比較 | = identical? not= not compare clojure.data/diff |
測試 | true? false? instance? nil? some? |
從集合建立 | seq vals keys rseq subseq rsubseq sequence |
從產生器函數建立 | lazy-seq repeatedly iterate (1.11) iteration |
從常數建立 | repeat range |
從其他 | file-seq line-seq resultset-seq re-seq tree-seq xml-seq iterator-seq enumeration-seq |
從 seq | keep keep-indexed |
萃取項目 | first second last rest next ffirst nfirst fnext nnext nth nthnext rand-nth when-first max-key min-key |
建立集合 | zipmap into reduce reductions set vec into-array to-array-2d mapv filterv |
傳遞給函式 | 套用 |
搜尋 | some filter |
強制評估 | doseq dorun doall run! |
檢查是否強制 | 已實現? |
現成 | map mapcat filter remove take take-while take-nth drop drop-while replace partition-by partition-all keep keep-indexed map-indexed distinct interpose cat dedupe random-sample (1.9) halt-when |
建立自己的 | completing ensure-reduced unreduced 另請參閱並發/揮發性部分 |
使用 | into sequence transduce eduction |
提早終止 | reduced reduced? deref |
運算 | valid? conform unform explain explain-data explain-str explain-out form describe assert check-asserts check-asserts? |
||
產生器運算 | gen exercise exercise-fn |
||
定義與註冊 | def fdef registry get-spec spec? spec with-gen |
||
邏輯 |
| ||
Regex | cat alt * + ? & keys* |
||
範圍 | |
||
其他 | nilable multi-spec fspec conformer |
||
自訂說明 | *explain-out* |
數字 | number? rational? integer? ratio? decimal? float? zero? (1.9) double? int? nat-int? neg-int? pos-int? |
符號、關鍵字 | keyword? symbol? (1.9) ident? qualified-ident? qualified-keyword? qualified-symbol? simple-ident? simple-keyword? simple-symbol? |
其他純量 | string? true? false? nil? some? (1.9) boolean? bytes? inst? uri? uuid? |
集合 | list? map? set? vector? associative? coll? sequential? seq? empty? (1.9) indexed? seqable? |
其他 | (1.9) any? |
轉換 ... | spit slurp(轉換為 writer/reader、Socket、包含檔名的字串、URI 等) |
轉換為 *out* | pr prn print printf println newline (clojure.pprint/) print-table |
轉換為 writer | (clojure.pprint/) pprint cl-format 還有:(binding [*out* writer] ...) |
轉換為字串 | format with-out-str pr-str prn-str print-str println-str |
從 *in* | read-line (clojure.edn/) read (clojure.tools.reader.edn/) read |
來自讀取器 | line-seq (clojure.edn/) read (clojure.tools.reader.edn/) read 還有:(binding [*in* reader] ...) java.io.Reader |
從字串 | with-in-str (clojure.edn/) read-string (clojure.tools.reader.edn/) read-string |
開啟 | with-open (clojure.java.io/) text: reader writer binary: input-stream output-stream |
二進制 | (.write ostream byte-arr) (.read istream byte-arr) java.io.OutputStream java.io.InputStream GitHub: gloss byte-spec |
雜項 | flush (.close s) file-seq *in* *out* *err* (clojure.java.io/) file copy delete-file resource as-file as-url as-relative-path GitHub: fs |
資料讀取器 | default-data-readers *default-data-reader-fn* |
tap | (1.10) tap> add-tap remove-tap |
建立 | fn defn defn- definline identity constantly memfn comp complement partial juxt memoize fnil every-pred some-fn |
呼叫 | apply -> ->> trampoline as-> cond-> cond->> some-> some->> |
測試 | fn? ifn? |
定義 |
| ||
延伸 null |
|
||
Reify |
|
||
測試 | satisfies? extends? |
||
其他 | extend extend-protocol extenders |
定義 |
|
存取 |
|
建立 | Pair. ->Pair map->Pair |
測試 | record? |
定義 |
|
存取 |
|
建立 | Pair. ->Pair |
有方法 |
|
定義 |
|
方法定義 |
|
分派 | get-method methods |
移除 | remove-method remove-all-methods |
偏好 | prefer-method prefers |
關係 | derive underive isa? parents ancestors descendants make-hierarchy |
建立 | defmacro definline |
偵錯 | macroexpand-1 macroexpand (clojure.walk/) macroexpand-all |
分支 | and or when when-not when-let when-first if-not if-let cond condp case when-some if-some |
迴圈 | for doseq dotimes while |
排列 | .. doto -> ->> as-> cond-> cond->> some-> some->> |
範圍 | binding locking time with-in-str with-local-vars with-open with-out-str with-precision with-redefs with-redefs-fn |
延遲 | lazy-cat lazy-seq delay |
文件。 | assert comment doc |
, |
逗號讀取為空白。通常用於映射鍵/值對之間,以提高可讀性。 |
' |
quote: |
/ |
命名空間分隔符號(請參閱基本類型/其他部分) |
\ |
字元字面值(請參閱基本類型/其他部分) |
: |
關鍵字(請參閱基本類型/其他部分) |
; |
單行註解 |
^ |
元資料(請參閱元資料部分) |
*foo* |
'earmuffs' - 表示 動態變數 的慣例,如果沒有動態,編譯器會發出警告 |
@ |
Deref: |
` |
語法引號 |
foo# |
'auto-gensym',在同一個 |
~ |
取消引號 |
~@ |
取消引號拼接 |
-> |
'thread first' 巨集 -> |
->> |
'thread last' 巨集 ->> |
>!! <!! >! <! |
core.async 通道巨集 >!! <!! >! <! |
( |
清單文字 (見集合/清單區段) |
[ |
向量文字 (見集合/向量區段) |
{ |
映射文字 (見集合/映射區段) |
#' |
變數引號: |
#" |
#"p" 讀取為正規表示法模式 p (見字串/正規表示法區段) |
#{ |
集合文字 (見集合/集合區段) |
#( |
匿名函式文字: |
% |
匿名函式引數: |
#? |
讀取條件: |
#?@ |
拼接讀取條件: |
#foo |
標記文字,例如: |
#: |
映射命名空間語法,例如: |
## |
(1.9) 符號值: |
$ |
|
foo? |
謂詞的慣用結尾,例如: zero? vector? instance?(未強制執行) |
foo! |
不安全操作的慣用結尾,例如: set! swap! alter-meta!(未強制執行) |
_ |
未使用的值的慣用名稱(未強制執行) |
#_ |
忽略下一個表單 |
一般 |
|
縮寫 |
|
常見 |
|
範例 |
|
在變數上 | meta with-meta vary-meta alter-meta! reset-meta! doc find-doc test |
繫結表單/解構 | (examples) let fn defn defmacro loop for doseq if-let when-let if-some when-some |
Def 變體 | def defn defn- definline defmacro defmethod defmulti defonce defrecord |
內部變數 | declare intern binding find-var var |
Var 物件 | with-local-vars var-get var-set alter-var-root var? bound? thread-bound? |
變數驗證器 | set-validator! get-validator |
目前 | *ns* |
建立/切換 | (教學) ns in-ns create-ns |
新增 | alias def import intern refer |
尋找 | all-ns find-ns |
檢查 | ns-name ns-aliases ns-map ns-interns ns-publics ns-refers ns-imports |
從符號 | resolve ns-resolve namespace the-ns (1.10) requiring-resolve |
移除 | ns-unalias ns-unmap remove-ns |
載入函式庫 | (tutorial) require use import refer |
載入清單 | loaded-libs |
載入雜項 | load load-file load-reader load-string |
建立 | ref |
檢查 | deref @ ( |
交易 | sync dosync io! |
在交易中 | ensure ref-set alter commute |
驗證器 | set-validator! get-validator |
歷史 | ref-history-count ref-min-history ref-max-history |
一般 | .. doto Classname/ Classname. new bean comparator enumeration-seq import iterator-seq memfn set! class class? bases supers type gen-class gen-interface definterface |
轉型 | boolean byte short char int long float double bigdec bigint num cast biginteger |
例外 | throw try catch finally pst ex-info ex-data Throwable->map (1.9) StackTraceElement->vec (1.10) ex-cause ex-message (clojure.main/) ex-triage ex-str err->msg report-error |
建立 | proxy get-proxy-class construct-proxy init-proxy |
雜項 | proxy-mappings proxy-super update-proxy |
建立 | zipper seq-zip vector-zip xml-zip |
取得位置 | up down left right leftmost rightmost |
取得序列 | lefts rights path children |
「變更」 | make-node replace edit insert-child insert-left insert-right append-child remove |
移動 | next prev |
雜項 | root node branch? end? |
XML | xml-seq |
REPL | *1 *2 *3 *e *print-dup* *print-length* *print-level* *print-meta* *print-readably* |
程式碼 | *compile-files* *compile-path* *file* *warn-on-reflection* compile loaded-libs test |
雜項 | eval force hash name *clojure-version* clojure-version *command-line-args* (1.11) random-uuid |
瀏覽器 / Shell | (clojure.java.browse/) browse-url (clojure.java.shell/) sh with-sh-dir with-sh-env |