clojure.repl/ doc find-doc apropos source pst javadoc ( is namespace for later syms)



Generic ops count empty not-empty into conj (clojure.walk/) walk prewalk prewalk-demo prewalk-replace postwalk postwalk-demo postwalk-replace
Content tests distinct? empty? every? not-every? some not-any?
Capabilities sequential? associative? sorted? counted? reversible?
Type tests coll? list? vector? set? map? seq? (1.6) record?


Create '() list list*
Examine first nth peek .indexOf .lastIndexOf
'Change' cons conj rest pop


Create [] vector vec vector-of
Examine (my-vec idx)( nth my-vec idx) get peek .indexOf .lastIndexOf
'Change' assoc pop subvec replace conj rseq
Ops (1.4) mapv filterv reduce-kv


Create #{} set hash-set sorted-set sorted-set-by
Examine (my-set item)( get my-set item) contains?
'Change' conj disj
Set ops (clojure.set/) union difference intersection select See also Relations
Test (clojure.set/) subset? superset?


Create {} hash-map array-map zipmap sorted-map sorted-map-by bean frequencies group-by (clojure.set/) index
Examine (:key my-map)( get my-map :key) get-in contains? find keys vals
'Change' assoc assoc-in dissoc merge merge-with select-keys update-in (clojure.set/) rename-keys map-invert GitHub: Medley
Entry key val
Sorted maps rseq subseq rsubseq

Relations (set of maps, each with same keys, aka rels)

Rel algebra (clojure.set/) join select project union difference intersection index rename

Transients (

Create transient persistent!
Change conj! pop! assoc! dissoc! disj! Note: always use return value for later changes, never original!


Compare = == identical? not= not compare
Test true? false? instance? nil? (1.6) some?


to/from ... spit slurp (to writer/from reader, Socket, string with file name, URI, etc.)
to *out* pr prn print printf println newline (clojure.pprint/) print-table
to writer (clojure.pprint/) pprint cl-format also: (binding [*out* writer] ...)
to string format with-out-str pr-str prn-str print-str println-str
from *in* read-line ( read
from reader line-seq ( read also: (binding [*in* reader] ...)
from string with-in-str ( read-string
Open with-open ( text: reader writer binary: input-stream output-stream
Binary (.write ostream byte-arr) (.read istream byte-arr) GitHub: gloss byte-spec
Misc flush (.close s) file-seq *in* *out* *err* ( file copy delete-file resource as-file as-url as-relative-path GitHub: fs
Data readers (1.4) *data-readers* default-data-readers (1.5) *default-data-reader-fn*

Abstractions (Clojure type selection flowchart)

Protocols (

Define ( defprotocol Slicey (slice [at]))
Extend ( extend-type String Slicey (slice [at] ...))
Extend null ( extend-type nil Slicey (slice [_] nil))
Reify ( reify Slicey (slice [at] ...))
Test satisfies? extends?
Other extend extend-protocol extenders

Records (

Define ( defrecord Pair [h t])
Access (:h (Pair. 1 2))1
Create Pair. ->Pair map->Pair
Test record?

Types (

Define ( deftype Pair [h t])
Access (.h (Pair. 1 2))1
Create Pair. ->Pair
With methods ( deftype Pair [h t]
  (toString [this] (str "<" h "," t ">")))

Multimethods (

Define ( defmulti my-mm dispatch-fn)
Method define ( defmethod my-mm :dispatch-value [args] ...)
Dispatch get-method methods
Remove remove-method remove-all-methods
Prefer prefer-method prefers
Relation derive isa? parents ancestors descendants make-hierarchy

Reader Macros

' Quote: 'form(quote form)
\ Character literal
; Single line comment
^ Metadata (see Metadata section)
@ Deref: @form(deref form)
` Syntax-quote
~ Unquote
~@ Unquote-splicing
#"p" Regex Pattern p
#' Var quote: #'x(var x)
#() #(...)(fn [args] (...))
#_ Ignore next form

Metadata (

General ^{:key1 val1 :key2 val2 ...}
Abbrevs ^Type^{:tag Type}
^:key^{:key true}
Common ^:dynamic ^:private ^:doc ^:const
Examples (defn ^:private ^String my-fn ...)
(def ^:dynamic *dyn-var* val)
On Vars meta with-meta vary-meta alter-meta! reset-meta! doc find-doc test


Load libs (tutorial) require use import refer
List loaded loaded-libs
Load misc load load-file load-reader load-string

this cheatsheet is based on