Cheatsheet Usletter Color
Cheatsheet Usletter Color
8, sheet v35)
Documentation
clojure.repl/
Primitives
Numbers
Literals
Arithmetic
Compare
Bitwise
Cast
Test
Random
BigDecimal
Unchecked
Strings
Create
Use
Regex
Letters
Trim
Test
Transients (clojure.org/reference/transients)
Create
transient persistent!
Change
conj! pop! assoc! dissoc! disj! Note: always use return value for later
changes, never original!
Misc
Compare
Test
Sequences
Creating a Lazy Seq
From collection
From producer fn
From constant
From other
From seq
str format "a string" "escapes \b\f\n\t\r\" octal \377 hex \ucafe"
See also section IO/to string
count get subs compare (clojure.string/) join escape split split-lines
replace replace-first reverse (1.8) index-of last-index-of
#"pattern" re-find re-seq re-matches re-pattern re-matcher re-groups
(clojure.string/) replace replace-first re-quote-replacement Note: \
in #"" is not escape char. (re-pattern "\\s*\\d+") can be written
#"\s*\d+"
(clojure.string/) capitalize lower-case upper-case
(clojure.string/) trim trim-newline triml trimr
string? (clojure.string/) blank? (1.8) starts-with? ends-with?
includes?
Other
Characters
Keywords
Symbols
Misc
Collections
Collections
Generic ops
Content tests
Capabilities
Type tests
Examine
Change
Set ops
Test
Sorted sets
Maps
Create unsorted
Create sorted
Examine
Change
Ops
Entry
Sorted maps
Rearrange
Process items
Using a Seq
Extract item
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
apply
some filter
doseq dorun doall (1.7) run!
realized?
Construct coll
Pass to fn
Search
Force evaluation
Check for forced
Transducers (clojure.org/reference/transducers)
Sets
Create unsorted
Create sorted
O the shelf
Zippers (clojure.zip/)
Create
zipper seq-zip vector-zip xml-zip
Get loc
up down left right leftmost rightmost
Get seq
lefts rights path children
Change
make-node replace edit insert-child insert-left insert-right
append-child remove
Move
next prev
Misc
root node branch? end?
IO
#{} set hash-set
sorted-set sorted-set-by (clojure.data.avl/) sorted-set
sorted-set-by (flatland.ordered.set/) ordered-set (clojure.data.intmap/) int-set dense-int-set
(my-set item) ( get my-set item) contains?
conj disj
(clojure.set/) union difference intersection select See also section Relations
(clojure.set/) subset? superset?
rseq subseq rsubseq
to/from
...
to *out*
to writer
Binary
spit slurp (to writer/from reader, Socket, string with file name, URI, etc.)
to string
from *in*
from reader
from string
Open
Misc
Data readers
Functions
Create
Call
Test
Loop
Arrange
Scope
Lazy
Doc.
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 (1.6) 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
/
\
:
;
*foo*
@
foo#
~
~@
->
->>
(
[
{
#
#"
#{
#(
%
#?
#?@
#foo
$
foo?
foo!
_
#_
Comma reads as white space. Often used between map key/value pairs for readability.
quote: form ( quote form)
Namespace separator (see Primitives/Other section)
Character literal (see Primitives/Other section)
Keyword (see Primitives/Other section)
Single line comment
Metadata (see Metadata section)
earmuffs - convention to indicate dynamic vars, compiler warns if
not dynamic
Deref: @form ( deref form)
Syntax-quote
auto-gensym, consistently replaced with same auto-generated symbol
everywhere inside same ( ... )
Unquote
Unquote-splicing
thread first macro ->
thread last macro ->>
List literal (see Collections/Lists section)
Vector literal (see Collections/Vectors section)
Map literal (see Collections/Maps section)
Var-quote #x ( var x)
#"p" reads as regex pattern p (see Strings/Regex section)
Set literal (see Collections/Sets section)
Anonymous function literal: #(...) (fn [args] (...))
Anonymous function argument: %N is value of anonymous function arg N.
% short for %1. %& for rest args.
(1.7) Reader conditional: #?(:clj x :cljs y) reads as x on JVM, y in
ClojureScript, nothing elsewhere. Other keys: :cljr :default
(1.7) Splicing reader conditional: [1 #?@(:clj [x y] :cljs [w z])
3] reads as [1 x y 3] on JVM, [1 w z 3] in ClojureScript, [1 3]
elsewhere.
tagged literal e.g. #inst #uuid
JavaContainerClass$InnerClass
conventional ending for a predicate, e.g.: zero? vector? instance?
(unenforced)
conventional ending for an unsafe operation, e.g.: set! swap!
alter-meta! (unenforced)
conventional name for an unused value (unenforced)
Ignore next form
def if do let letfn quote var fn loop recur set! throw try monitor-enter
monitor-exit
Binding Forms /
(examples) let fn defn defmacro loop for doseq if-let
Destructuring
when-let (1.6) if-some when-some
Namespace
Current
Create/Switch
Add
Find
Examine
From symbol
Remove
*ns*
(tutorial) 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
ns-unalias ns-unmap remove-ns
Loading
Load libs
List loaded
Load misc
Concurrency
Atoms
Futures
Macros
Create
Debug
Branch
Threads
Volatiles
Misc
Cast
Exceptions
Arrays
Create
Use
Cast
Other
XML
REPL
Code
Misc
Browser
/ Shell
clojure.xml/parse xml-seq
*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*
(clojure.java.browse/) browse-url (clojure.java.shell/) sh with-sh-dir
with-sh-env