# Quickref for Clojure Core

## Simple Values

### Simple Values

#### Numbers > Arithmetic

+
Returns the sum of nums. (+) returns 0. Does not auto-promote longs, will throw on overflow. See also: +'
-
If no ys are supplied, returns the negation of x, else subtracts the ys from x and returns the result. Does
*
Returns the product of nums. (*) returns 1. Does not auto-promote longs, will throw on overflow. See also: *
/
If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the denominat
quot
quot[ient] of dividing numerator by denominator.
rem
remainder of dividing numerator by denominator.
mod
Modulus of num and div. Truncates toward negative infinity.
inc
Returns a number one greater than num. Does not auto-promote longs, will throw on overflow. See also: inc'
dec
Returns a number one less than num. Does not auto-promote longs, will throw on overflow. See also: dec'
max
Returns the greatest of the nums.
min
Returns the least of the nums.
with-precision
Sets the precision and rounding mode to be used for BigDecimal operations. Usage: (with-precision 10 (/ 1M
numerator
Returns the numerator part of a Ratio.
denominator
Returns the denominator part of a Ratio.
rand
Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive).
rand-int
Returns a random integer between 0 (inclusive) and n (exclusive).

#### Numbers > Compare

=
Equality. Returns true if x equals y, false if not. Same as Java x.equals(y) except it also works for nil, a
==
Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
not=
Same as (not (= obj1 obj2))
<
Returns non-nil if nums are in monotonically increasing order, otherwise false.
>
Returns non-nil if nums are in monotonically decreasing order, otherwise false.
<=
Returns non-nil if nums are in monotonically non-decreasing order, otherwise false.
>=
Returns non-nil if nums are in monotonically non-increasing order, otherwise false.

#### Numbers > Bitwise Operations

bit-and
Bitwise and
bit-or
Bitwise or
bit-xor
Bitwise exclusive or
bit-flip
Flip bit at index n
bit-not
Bitwise complement
bit-and-not
Bitwise and with complement
bit-clear
Clear bit at index n
bit-set
Set bit at index n
bit-shift-left
Bitwise shift left
bit-shift-right
Bitwise shift right
bit-test
Test bit at index n

#### Numbers > Cast

byte
Coerce to byte
short
Coerce to short
int
Coerce to int
long
Coerce to long
float
Coerce to float
double
Coerce to double
bigint
Coerce to BigInt
bigdec
Coerce to BigDecimal
num
Coerce to Number
rationalize
returns the rational value of num

#### Numbers > Test

identical?
Tests if 2 arguments are the same object
zero?
Returns true if num is zero, else false
pos?
Returns true if num is greater than zero, else false
neg?
Returns true if num is less than zero, else false
even?
Returns true if n is even, throws an exception if n is not an integer
odd?
Returns true if n is odd, throws an exception if n is not an integer
number?
Returns true if x is a Number
ratio?
Returns true if n is a Ratio
rational?
Returns true if n is a rational number
integer?
Returns true if n is an integer
int?
Return true if x is a fixed precision integer
pos-int?
Return true if x is a positive fixed precision integer
nat-int?
Return true if x is a non-negative fixed precision integer
decimal?
Returns true if n is a BigDecimal
bigdec?
Return true if x is a BigDecimal
float?
Returns true if n is a floating point number
double?
Return true if x is a Double

### Simple Values

#### Booleans > Test

nil?
Returns true if x is nil, false otherwise.
true?
Returns true if x is the value true, false otherwise.
false?
Returns true if x is the value false, false otherwise.

#### Booleans > Cast

boolean
Coerce to boolean

### Simple Values

#### Symbols / Keywords > Create

keyword
Returns a Keyword with the given namespace and name. Do not use : in the keyword strings, it will be added
symbol
Returns a Symbol with the given namespace and name.

#### Symbols / Keywords > Use

name
Returns the name String of a string, symbol or keyword.
intern
Finds or creates a var named by the symbol name in the namespace ns (which can be a symbol or a namespace),
namespace
Returns the namespace String of a symbol or keyword, or nil if not present.

#### Symbols / Keywords > Test

keyword?
Return true if x is a Keyword
symbol?
Return true if x is a Symbol
ident?
Return true if x is a symbol or keyword
simple-keyword?
Return true if x is a keyword without a namespace
simple-symbol?
Return true if x is a symbol without a namespace
simple-ident?
Return true if x is a symbol or keyword without a namespace
qualified-keyword?
Return true if x is a keyword with a namespace
qualified-symbol?
Return true if x is a symbol with a namespace
qualified-ident?
Return true if x is a symbol or keyword with a namespace

### Simple Values

#### Strings / Characters > Create

str
With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty s
print-str
print to a string, returning it
println-str
println to a string, returning it
pr-str
pr to a string, returning it
prn-str
prn to a string, returning it
with-out-str
Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by

#### Strings / Characters > Use

count
Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Ja
get
Returns the value mapped to key, not-found or nil if key not present.
subs
Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), e
format
Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax

#### Strings / Characters > Cast / Test

char
Coerce to char
char?
Return true if x is a Character
string?
Return true if x is a String

### Simple Values

#### Regular Expressions > Create

re-pattern
Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.
re-matcher
Returns an instance of java.util.regex.Matcher, for use, e.g. in re-find.

#### Regular Expressions > Use

re-find
Returns the next regex match, if any, of string to pattern, using java.util.regex.Matcher.find(). Uses re-g
re-matches
Returns the match, if any, of string to pattern, using java.util.regex.Matcher.matches(). Uses re-groups to
re-seq
Returns a lazy sequence of successive matches of pattern in string, using java.util.regex.Matcher.find(), ea
re-groups
Returns the groups from the most recent match/find. If there are no nested groups, returns a string of the e

## Operations

### Operations

#### Flow Control > Boolean

not
Returns true if x is logical false, false otherwise.
and
Evaluates exprs one at a time, from left to right. If a form returns logical false (nil or false), and retur
or
Evaluates exprs one at a time, from left to right. If a form returns a logical true value, or returns that v

#### Flow Control > Normal

let
binding => binding-form init-expr Evaluates the exprs in a lexical context in which the symbols in the bi
if
Evaluates test.
if-not
Evaluates test. If logical false, evaluates and returns then expr, otherwise else expr, if supplied, else n
if-let
bindings => binding-form test If test is true, evaluates then with binding-form bound to the value of te
if-some
bindings => binding-form test If test is not nil, evaluates then with binding-form bound to the value o
when
Evaluates test. If logical true, evaluates body in an implicit do.
when-not
Evaluates test. If logical false, evaluates body in an implicit do.
when-let
bindings => binding-form test When test is true, evaluates body with binding-form bound to the value of tes
when-first
bindings => x xs Roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only onc
when-some
bindings => binding-form test When test is not nil, evaluates body with binding-form bound to the value
cond
Takes a set of test/expr pairs. It evaluates each test one at a time. If a test returns logical true, cond
condp
Takes a binary predicate, an expression, and a set of clauses. Each clause can take the form of either: t
cond->
Takes an expression and a set of test/form pairs. Threads expr (via ->) through each form for which the corr
cond->>
Takes an expression and a set of test/form pairs. Threads expr (via ->>) through each form for which the cor
some->
When expr is not nil, threads it into the first form (via ->), and when that result is not nil, through the
some->>
When expr is not nil, threads it into the first form (via ->>), and when that result is not nil, through the
as->
Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that
case
Takes an expression, and a set of clauses. Each clause can take the form of either: test-constant result
do
Evaluates the expressions in order and returns the value of the last. If no expressions are supplied, returns
eval
Evaluates the form data structure (not text!) and returns the result.
loop
Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respec
recur
Evaluates the exprs in order, then, in parallel, rebinds the bindings of the recursion point to the values of
trampoline
trampoline can be used to convert algorithms requiring mutual recursion without stack consumption. Calls f w
while
Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become

#### Flow Control > Exceptional

try
The exprs are evaluated and, if no exceptions occur, the value of the last is returned. If an exception occurs
catch
The exprs are evaluated and, if no exceptions occur, the value of the last is returned. If an exception occurs
finally
The exprs are evaluated and, if no exceptions occur, the value of the last is returned. If an exception occurs
throw
The expr is evaluated and thrown, therefore it should yield an instance of some derivee of Throwable. Please s
assert
Evaluates expr and throws an exception if it does not evaluate to logical true.

#### Flow Control > Delay

delay
Takes a body of expressions and yields a Delay object that will invoke the body only the first time it is fo
delay?
returns true if x is a Delay created with delay
deref
Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction, returns the in-tran
force
If x is a Delay, returns the (possibly cached) value of its expression, else returns x

#### Flow Control > Function Based

repeatedly
Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied)
iterate
Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects

#### Flow Control > Sequence Based

dotimes
bindings => name n Repeatedly executes body (presumably for side-effects) with name bound to integers fro
doseq
Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by "for". Do
for
List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero

#### Flow Control > Laziness

lazy-seq
Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the bo
lazy-cat
Expands to code which yields a lazy sequence of the concatenation of the supplied colls. Each coll expr is
doall
When lazy sequences are produced via functions that have side effects, any effects other than those needed t
dorun
When lazy sequences are produced via functions that have side effects, any effects other than those needed t

### Operations

#### Type Inspection > Clojure Types

type
Returns the :type metadata of x, or its Class if none
extends?
Returns true if atype extends protocol
satisfies?
Returns true if x satisfies the protocol

#### Type Inspection > Java Types

class
Returns the Class of x
bases
Returns the immediate superclass and direct interfaces of c, if any
supers
Returns the immediate and indirect superclasses and interfaces of c, if any
class?
Returns true if x is an instance of Class
instance?
Evaluates x and tests if it is an instance of the class c. Returns true or false
isa?
Returns true if (= child parent), or child is directly or indirectly derived from parent, either via a Java
cast
Throws a ClassCastException if x is not a c, else returns x.

### Operations

#### Concurrency > General

deref
Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction, returns the in-tran
get-validator
Gets the validator-fn for a var/ref/agent/atom.
set-validator!
Sets the validator-fn for a var/ref/agent/atom. validator-fn must be nil or a side-effect-free fn of one arg

#### Concurrency > Atoms

atom
Creates and returns an Atom with an initial value of x and zero or more options (in any order): :meta met
swap!
Atomically swaps the value of atom to be: (apply f current-value-of-atom args). Note that f may be called
reset!
Sets the value of atom to newval without regard for the current value. Returns newval.
compare-and-set!
Atomically sets the value of atom to newval if and only if the current value of the atom is identical to old

#### Concurrency > Refs

ref
Creates and returns a Ref with an initial value of x and zero or more options (in any order): :meta metad
sync
transaction-flags => TBD, pass nil for now Runs the exprs (in an implicit do) in a transaction that encompa
dosync
Runs the exprs (in an implicit do) in a transaction that encompasses exprs and any nested calls. Starts a t
ref-set
Must be called in a transaction. Sets the value of ref. Returns val.
alter
Must be called in a transaction. Sets the in-transaction-value of ref to: (apply fun in-transaction-value
commute
Must be called in a transaction. Sets the in-transaction-value of ref to: (apply fun in-transaction-value
ensure
Must be called in a transaction. Protects the ref from modification by other transactions. Returns the in-t
io!
If an io! block occurs in a transaction, throws an IllegalStateException, else runs body in an implicit do.
ref-history-count
Returns the history count of a ref
ref-max-history
Gets the max-history of a ref, or sets it and returns the ref
ref-min-history
Gets the min-history of a ref, or sets it and returns the ref

#### Concurrency > Agents

agent
Creates and returns an agent with an initial value of state and zero or more options (in any order): :met
send
Dispatch an action to an agent. Returns the agent immediately. Subsequently, in a thread from a thread pool,
send-off
Dispatch a potentially blocking action to an agent. Returns the agent immediately. Subsequently, in a separa
await
Blocks the current thread (indefinitely!) until all actions dispatched thus far, from this thread or agent,
await-for
Blocks the current thread until all actions dispatched thus far (from this thread or agent) to the agents ha
agent-error
Returns the exception thrown during an asynchronous action of the agent if the agent is failed. Returns nil
restart-agent
When an agent is failed, changes the agent state to new-state and then un-fails the agent so that sends are
shutdown-agents
Initiates a shutdown of the thread pools that back the agent system. Running actions will complete, but no n
*agent*
The agent currently running an action on this thread, else nil
agent-errors
DEPRECATED: Use 'agent-error' instead. Returns a sequence of the exceptions thrown during asynchronous act
error-handler
Returns the error-handler of agent a, or nil if there is none. See set-error-handler!
set-error-handler!
Sets the error-handler of agent a to handler-fn. If an action being run by the agent throws an exception or
error-mode
Returns the error-mode of agent a. See set-error-mode!
set-error-mode!
Sets the error-mode of agent a to mode-keyword, which must be either :fail or :continue. If an action being
release-pending-sends
Normally, actions sent directly or indirectly during another action are held until the action completes (cha

#### Concurrency > Futures

future
Takes a body of expressions and yields a future object that will invoke the body in another thread, and will
future-call
Takes a function of no args and yields a future object that will invoke the function in another thread, and
future-done?
Returns true if future f is done
future-cancel
Cancels the future, if possible.
future-cancelled?
Returns true if future f is cancelled
future?
Returns true if x is a future

#### Concurrency > Volatiles

volatile!
Creates and returns a Volatile with an initial value of val.
vswap!
Non-atomically swaps the value of the volatile as if: (apply f current-value-of-vol args). Returns the valu
vreset!
Sets the value of volatile to newval without regard for the current value. Returns newval.

#### Concurrency > Thread Local Values

bound-fn
Returns a function defined by the given fntail, which will install the same bindings in effect as in the thr
bound-fn*
Returns a function, which will install the same bindings in effect as in the thread at the time bound-fn* wa
Get a map with the Var/value pairs which is currently in effect for the current thread.
WARNING: This is a low-level function. Prefer high-level macros like binding where ever possible. Takes a
Pop one set of bindings pushed with push-binding before. It is an error to pop bindings without pushing befo
Returns true if all of the vars provided as arguments have thread-local bindings. Implies that set!'ing the

#### Concurrency > Misc

locking
Executes exprs in an implicit do, while holding the monitor of x. Will release the monitor of x in all circu
pcalls
Executes the no-arg fns in parallel, returning a lazy sequence of their values
pvalues
Returns a lazy sequence of the values of the exprs, which are evaluated in parallel
pmap
Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the con
seque
Creates a queued seq on another (presumably lazy) seq s. The queued seq will produce a concrete seq in the b
promise
Returns a promise object that can be read with deref/@, and set, once only, with deliver. Calls to deref/@ p
deliver
Delivers the supplied value to the promise, releasing any pending derefs. A subsequent call to deliver on a
Adds a watch function to an agent/atom/var/ref reference. The watch fn must be a fn of 4 args: a key, the re
remove-watch
Removes a watch (set by add-watch) from a reference

## Functions

### Functions

#### General > Create

fn
params => positional-params* , or positional-params* & next-param positional-param => binding-form next-pa
defn
Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-string or a
defn-
same as defn, yielding non-public def
definline
Experimental - like defmacro, except defines a named function whose body is the expansion, calls to which ma
identity
Returns its argument.
constantly
Returns a function that takes any number of arguments and returns x.
memfn
Expands into code that creates a fn that expects to be passed an object and any args and calls the named ins
comp
Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a var
complement
Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns
comparator
Returns an implementation of java.util.Comparator based upon pred.
fnil
Takes a function f, and returns a function that calls f, replacing a nil first argument to f with the suppli
partial
Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number o
juxt
Takes a set of functions and returns a fn that is the juxtaposition of those fns. The returned fn takes a v
memoize
Returns a memoized version of a referentially transparent function. The memoized version of the function kee
some-fn
Takes a set of predicates and returns a function f that returns the first logical true value returned by one
every-pred
Takes a set of predicates and returns a function f that returns true if all of its composing predicates retu

#### General > Call

->
Threads the expr through the forms. Inserts x as the second item in the first form, making a list of it if i
->>
Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it
apply
Applies fn f to the argument list formed by prepending intervening arguments to args.

#### General > Test

fn?
Returns true if x implements Fn, i.e. is an object created via fn.
ifn?
Returns true if x implements IFn. Note that many data structures (e.g. sets and maps) implement IFn

#### General > Misc

compare
Comparator. Returns a negative number, zero, or a positive number when x is logically 'less than', 'equal to
hash
Returns the hash code of its argument. Note this is the hash code consistent with =, and thus is different t

### Functions

#### Multifunctions > Create

defmulti
Creates a new multimethod with the associated dispatch function. The docstring and attr-map are optional.
defmethod
Creates and installs a new method of multimethod associated with dispatch-value.

#### Multifunctions > Inspect and Modify

get-method
Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, or nil if
methods
Given a multimethod, returns a map of dispatch values -> dispatch fns
prefer-method
Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y when there is a conflict
prefers
Given a multimethod, returns a map of preferred value -> set of other values
remove-method
Removes the method of multimethod associated with dispatch-value.
remove-all-methods
Removes all of the methods of multimethod.

### Functions

#### Macros > Create

defmacro
Like defn, but the resulting function name is declared as a macro and will be used as a macro by the compile
macroexpand
Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note ne
macroexpand-1
If form represents a macro form, returns its expansion, else returns form.
gensym
Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix# where # is some

### Functions

#### Java Interop > Objects

doto
Evaluates x then calls all of the methods and functions with the value of x supplied at the front of the giv
..
form => fieldName-symbol or (instanceMethodName-symbol args*) Expands into a member access (.) of the first
set!
Assignment special form. When the first operand is a field member access form, the assignment is to the corres

#### Java Interop > Array Creation

make-array
Creates and returns an array of instances of the specified class of the specified dimension(s). Note that a
object-array
Creates an array of objects
boolean-array
Creates an array of booleans
byte-array
Creates an array of bytes
char-array
Creates an array of chars
short-array
Creates an array of shorts
int-array
Creates an array of ints
long-array
Creates an array of longs
float-array
Creates an array of floats
double-array
Creates an array of doubles
aclone
Returns a clone of the Java array. Works on arrays of known types.
to-array
Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to java.util
to-array-2d
Returns a (potentially-ragged) 2-dimensional array of Objects containing the contents of coll, which can be
into-array
Returns an array with components set to the values in aseq. The array's component type is type if provided,

#### Java Interop > Array Use

aget
Returns the value at the index/indices. Works on Java arrays of all types.
aset
Sets the value at the index/indices. Works on Java arrays of reference types. Returns val.
aset-boolean
Sets the value at the index/indices. Works on arrays of boolean. Returns val.
aset-char
Sets the value at the index/indices. Works on arrays of char. Returns val.
aset-byte
Sets the value at the index/indices. Works on arrays of byte. Returns val.
aset-int
Sets the value at the index/indices. Works on arrays of int. Returns val.
aset-long
Sets the value at the index/indices. Works on arrays of long. Returns val.
aset-short
Sets the value at the index/indices. Works on arrays of short. Returns val.
aset-float
Sets the value at the index/indices. Works on arrays of float. Returns val.
aset-double
Sets the value at the index/indices. Works on arrays of double. Returns val.
alength
Returns the length of the Java array. Works on arrays of all types.
amap
Maps an expression across an array a, using an index named idx, and return value named ret, initialized to a
areduce
Reduces an expression across an array a, using an index named idx, and return value named ret, initialized t

#### Java Interop > Casting

booleans
Casts to boolean[]
bytes
Casts to bytes[]
chars
Casts to chars[]
ints
Casts to int[]
shorts
Casts to shorts[]
longs
Casts to long[]
floats
Casts to float[]
doubles
Casts to double[]

### Functions

#### Proxies > Create

proxy
class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the supercl
get-proxy-class
Takes an optional single class followed by zero or more interfaces. If not supplied class defaults to Object
construct-proxy
Takes a proxy class and any arguments for its superclass ctor and creates and returns an instance of the pro
init-proxy
Takes a proxy instance and a map of strings (which must correspond to methods of the proxy superclass/superi

#### Proxies > Misc

proxy-mappings
Takes a proxy instance and returns the proxy's fn map.
proxy-super
Use to call a superclass method in the body of a proxy method. Note, expansion captures 'this
update-proxy
Takes a proxy instance and a map of strings (which must correspond to methods of the proxy superclass/superi

## Collections

### Collections

#### Collections > Generic Operations

count
Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Ja
empty
Returns an empty collection of the same category as coll, or nil
not-empty
If coll is empty, returns nil, else coll
into
Returns a new coll consisting of to-coll with all of the items of from-coll conjoined. A transducer may be s
conj
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' m

#### Collections > Content Tests

contains?
Returns true if key is present in the given collection, otherwise returns false. Note that for numerically
distinct?
Returns true if no two of the arguments are =
empty?
Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not
every?
Returns true if (pred x) is logical true for every x in coll, else false.
not-every?
Returns false if (pred x) is logical true for every x in coll, else true.
some
Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a
not-any?
Returns false if (pred x) is logical true for any x in coll, else true.

#### Collections > Capabilities

sequential?
Returns true if coll implements Sequential
associative?
Returns true if coll implements Associative
sorted?
Returns true if coll implements Sorted
counted?
Returns true if coll implements count in constant time
reversible?
Returns true if coll implements Reversible

#### Collections > Type Tests

coll?
Returns true if x implements IPersistentCollection
seq?
Return true if x implements ISeq
vector?
Return true if x implements IPersistentVector
list?
Returns true if x implements IPersistentList
map?
Return true if x implements IPersistentMap
set?
Returns true if x implements IPersistentSet

### Collections

#### Vectors > Create

vec
Creates a new vector containing the contents of coll. Java arrays will be aliased and should not be modified
vector
Creates a new vector containing the args.
vector-of
Creates a new vector of a single primitive type t, where t is one of :int :long :float :double :byte :short

#### Vectors > Use

conj
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' m
peek
For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collec
pop
For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector wit
get
Returns the value mapped to key, not-found or nil if key not present.
assoc
assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the
subvec
Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not
rseq
Returns, in constant time, a seq of the items in rev (which can be a vector or sorted-map), in reverse order

### Collections

#### Lists > Create

list
Creates a new list containing the items.
list*
Creates a new seq containing the items prepended to the rest, the last of which will be treated as a sequenc

#### Lists > Use

cons
Returns a new seq where x is the first element and seq is the rest.
conj
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' m
peek
For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collec
pop
For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector wit
first
Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.
rest
Returns a possibly empty seq of the items after the first. Calls seq on its argument.

### Collections

#### Maps > Create

hash-map
keyval => key val Returns a new hash map with supplied mappings. If any keys are equal, they are handled
array-map
Constructs an array-map. If any keys are equal, they are handled as if by repeated uses of assoc.
zipmap
Returns a map with the keys mapped to the corresponding vals.
sorted-map
keyval => key val Returns a new sorted map with supplied mappings. If any keys are equal, they are handle
sorted-map-by
keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator. If any
bean
Takes a Java object and returns a read-only implementation of the map abstraction based upon its JavaBean pr
frequencies
Returns a map from distinct items in coll to the number of times they appear.

#### Maps > Use

assoc
assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the
assoc-in
Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value
dissoc
dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)
find
Returns the map entry for key, or nil if key not present.
key
Returns the key of the map entry.
val
Returns the value in the map entry.
keys
Returns a sequence of the map's keys, in the same order as (seq map).
vals
Returns a sequence of the map's values, in the same order as (seq map).
get
Returns the value mapped to key, not-found or nil if key not present.
get-in
Returns the value in a nested associative structure, where ks is a sequence of keys. Returns nil if the key
update
'Updates' a value in an associative structure, where k is a key and f is a function that will take the old v
update-in
'Updates' a value in a nested associative structure, where ks is a sequence of keys and f is a function that
select-keys
Returns a map containing only those entries in map whose key is in keys
merge
Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than on
merge-with
Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than on
reduce-kv
Reduces an associative collection. f should be a function of 3 arguments. Returns the result of applying f t

#### Maps > Use (Sorted Collections)

rseq
Returns, in constant time, a seq of the items in rev (which can be a vector or sorted-map), in reverse order
subseq
sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek f
rsubseq
sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a reverse seq of those entries with k

### Collections

#### Sets > Create

hash-set
Returns a new hash set with supplied keys. Any equal keys are handled as if by repeated uses of conj.
set
Returns a set of the distinct elements of coll.
sorted-set
Returns a new sorted set with supplied keys. Any equal keys are handled as if by repeated uses of conj.
sorted-set-by
Returns a new sorted set with supplied keys, using the supplied comparator. Any equal keys are handled as i

#### Sets > Use

conj
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' m
disj
disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s).
get
Returns the value mapped to key, not-found or nil if key not present.

### Collections

#### Structs > Create

defstruct
Same as (def name (create-struct keys...))
create-struct
Returns a structure basis object.
struct
Returns a new structmap instance with the keys of the structure-basis. vals must be supplied for basis keys
struct-map
Returns a new structmap instance with the keys of the structure-basis. keyvals may contain all, some or none
accessor
Returns a fn that, given an instance of a structmap with the basis, returns the value at the key. The key m

#### Structs > Use

get
Returns the value mapped to key, not-found or nil if key not present.
assoc
assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the

### Collections

#### Sequences > Create

seq
Returns a seq on the collection. If the collection is empty, returns nil. (seq nil) returns nil. seq also
sequence
Coerces coll to a (possibly empty) sequence, if it is not already one. Will not force a lazy seq. (sequence
eduction
Returns a reducible/iterable application of the transducers to the items in coll. Transducers are applied in
repeat
Returns a lazy (infinite!, or length n if supplied) sequence of xs.
replicate
DEPRECATED: Use 'repeat' instead. Returns a lazy seq of n xs.
range
Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, where start defaults to 0, st
repeatedly
Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied)
iterate
Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects
lazy-seq
Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the bo
lazy-cat
Expands to code which yields a lazy sequence of the concatenation of the supplied colls. Each coll expr is
cycle
Returns a lazy (infinite!) sequence of repetitions of the items in coll.
interleave
Returns a lazy seq of the first item in each coll, then the second etc.
interpose
Returns a lazy seq of the elements of coll separated by sep. Returns a stateful transducer when no collectio
tree-seq
Returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg tha
xml-seq
A tree seq on the xml elements as per xml/parse
enumeration-seq
Returns a seq on a java.util.Enumeration
iterator-seq
Returns a seq on a java.util.Iterator. Note that most collections providing iterators implement Iterable and
file-seq
A tree seq on java.io.Files
line-seq
Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.
resultset-seq
Creates and returns a lazy sequence of structmaps corresponding to the rows in the java.sql.ResultSet rs

#### Sequences > Use (General)

first
Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.
second
Same as (first (next x))
last
Return the last item in coll, in linear time
rest
Returns a possibly empty seq of the items after the first. Calls seq on its argument.
next
Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns
ffirst
Same as (first (first x))
nfirst
Same as (next (first x))
fnext
Same as (first (next x))
nnext
Same as (next (next x))
nth
Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-f
nthnext
Returns the nth next of coll, (seq coll) when n is 0.
nthrest
Returns the nth rest of coll, coll when n is 0.
rand-nth
Return a random element of the (sequential) collection. Will have the same performance characteristics as nt
butlast
Return a seq of all but the last item in coll, in linear time
take
Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n. Returns a sta
take-last
Returns a seq of the last n items in coll. Depending on the type of coll may be no better than linear time.
take-nth
Returns a lazy seq of every nth item in coll. Returns a stateful transducer when no collection is provided.
take-while
Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of s
drop
Returns a lazy sequence of all but the first n items in coll. Returns a stateful transducer when no collecti
drop-last
Return a lazy sequence of all but the last n (default 1) items in coll
drop-while
Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns logi

#### Sequences > Use ('Modification')

conj
conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' m
concat
Returns a lazy seq representing the concatenation of the elements in the supplied colls.
distinct
Returns a lazy sequence of the elements of coll with duplicates removed. Returns a stateful transducer when
group-by
Returns a map of the elements of coll keyed by the result of f on each element. The value at each key will b
partition
Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults t
partition-all
Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the e
partition-by
Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of parti
split-at
Returns a vector of [(take n coll) (drop n coll)]
split-with
Returns a vector of [(take-while pred coll) (drop-while pred coll)]
filter
Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-e
filterv
Returns a vector of the items in coll for which (pred item) returns true. pred must be free of side-effects.
remove
Returns a lazy sequence of the items in coll for which (pred item) returns false. pred must be free of side-
replace
Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in
shuffle
Return a random permutation of coll
random-sample
Returns items from coll with random probability of prob (0.0 - 1.0). Returns a transducer when no collectio
flatten
Takes any nested combination of sequential things (lists, vectors, etc.) and returns their contents as a sin
sort
Returns a sorted sequence of the items in coll. If no comparator is supplied, uses compare. comparator must
sort-by
Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item)
reverse
Returns a seq of the items in coll in reverse order. Not lazy.
dedupe
Returns a lazy sequence removing consecutive duplicates in coll. Returns a transducer when no collection is

#### Sequences > Use (Iteration)

for
List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero
doseq
Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by "for". Do
map
Returns a lazy sequence consisting of the result of applying f to the set of first items of each coll, follo
mapv
Returns a vector consisting of the result of applying f to the set of first items of each coll, followed by
map-indexed
Returns a lazy sequence consisting of the result of applying f to 0 and the first item of coll, followed by
keep
Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be inc
keep-indexed
Returns a lazy sequence of the non-nil results of (f index item). Note, this means false return values will
mapcat
Returns the result of applying concat to the result of applying map to f and colls. Thus function f should
reduce
f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first
reductions
Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with i
transduce
reduce with a transformation of f (xf). If init is not supplied, (f) will be called to produce it. f should
max-key
Returns the x for which (k x), a number, is greatest.
min-key
Returns the x for which (k x), a number, is least.
doall
When lazy sequences are produced via functions that have side effects, any effects other than those needed t
dorun
When lazy sequences are produced via functions that have side effects, any effects other than those needed t

### Collections

#### Transients > Create

transient
Returns a new, transient version of the collection, in constant time.
persistent!
Returns a new, persistent version of the transient collection, in constant time. The transient collection ca

#### Transients > Use (General)

conj!
Adds x to the transient collection, and return coll. The 'addition' may happen at different 'places' dependi
pop!
Removes the last item from a transient vector. If the collection is empty, throws an exception. Returns coll
assoc!
When applied to a transient map, adds mapping of key(s) to val(s). When applied to a transient vector, sets
dissoc!
Returns a transient map that doesn't contain a mapping for key(s).
disj!
disj[oin]. Returns a transient set of the same (hashed/sorted) type, that does not contain key(s).

## Code Structure

### Code Structure

#### Variables > Create

def
Creates and interns or locates a global var with the name of symbol and a namespace of the value of the curren
defonce
defs name to have the root value of the expr iff the named var has no root value, else expr is unevaluated
intern
Finds or creates a var named by the symbol name in the namespace ns (which can be a symbol or a namespace),
declare
defs the supplied var names with no bindings, useful for making forward declarations.

#### Variables > Use

set!
Assignment special form. When the first operand is a field member access form, the assignment is to the corres
alter-var-root
Atomically alters the root binding of var v by applying f to its current value plus any args
binding
binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the supplied i
with-bindings
Takes a map of Var/value pairs. Installs for the given Vars the associated values as thread-local bindings.
with-bindings*
Takes a map of Var/value pairs. Installs for the given Vars the associated values as thread-local bindings.
with-local-vars
varbinding=> symbol init-expr Executes the exprs in a context in which the symbols are bound to vars with
letfn
fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+) Takes a vector of function specs and a bod
gensym
Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix# where # is some

#### Variables > Inspect

var
The symbol must resolve to a var, and the Var object itself (not its value) is returned. The reader macro #'x
find-var
Returns the global var named by the namespace-qualified symbol, or nil if no var with that name.
var-get
Gets the value in the var object
var?
Returns true if v is of type clojure.lang.Var
bound?
Returns true if all of the vars provided as arguments have any bound value, root or thread-local. Implies t
resolve
same as (ns-resolve *ns* symbol) or (ns-resolve *ns* &env symbol)
ns-resolve
Returns the var or Class to which a symbol will be resolved in the namespace (unless found in the environmen
special-symbol?
Returns true if s names a special form

### Code Structure

#### Namespaces > Create & Delete

ns
Sets *ns* to the namespace named by name (unevaluated), creating it if needed. references can be zero or mo
create-ns
Create a new namespace named by the symbol if one doesn't already exist, returns it or the already-existing
remove-ns
Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace.

#### Namespaces > Inspect

*ns*
A clojure.lang.Namespace object representing the current namespace.
ns-name
Returns the name of the namespace, a symbol.
all-ns
Returns a sequence of all namespaces.
the-ns
If passed a namespace, returns it. Else, when passed a symbol, returns the namespace named by it, throwing a
find-ns
Returns the namespace named by the symbol or nil if it doesn't exist.
ns-publics
Returns a map of the public intern mappings for the namespace.
ns-interns
Returns a map of the intern mappings for the namespace.
ns-refers
Returns a map of the refer mappings for the namespace.
ns-aliases
Returns a map of the aliases for the namespace.
ns-imports
Returns a map of the import mappings for the namespace.
ns-map
Returns a map of all the mappings for the namespace.

#### Namespaces > Use

in-ns
Sets *ns* to the namespace named by the symbol, creating it if needed.
ns-resolve
Returns the var or Class to which a symbol will be resolved in the namespace (unless found in the environmen
ns-unalias
Removes the alias for the symbol from the namespace.
ns-unmap
Removes the mappings for the symbol from the namespace.
alias
Add an alias in the current namespace to another namespace. Arguments are two symbols: the alias to be used,

#### Namespaces > Misc

namespace-munge
Convert a Clojure namespace name to a legal Java package name.

### Code Structure

#### Hierarchies > General

make-hierarchy
Creates a hierarchy object for use with derive, isa? etc.
derive
Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol
underive
Removes a parent/child relationship between parent and tag. h must be a hierarchy obtained from make-hierarc
parents
Returns the immediate parents of tag, either via a Java type inheritance relationship or a relationship esta
ancestors
Returns the immediate and indirect parents of tag, either via a Java type inheritance relationship or a rela
descendants
Returns the immediate and indirect children of tag, through a relationship established via derive. h must be
isa?
Returns true if (= child parent), or child is directly or indirectly derived from parent, either via a Java

### Code Structure

#### User Defined Types > General

defprotocol
A protocol is a named set of named methods and their signatures: (defprotocol AProtocolName ;optional d
defrecord
(defrecord name [fields*] options* specs*) Options are expressed as sequential keywords and arguments (in
deftype
(deftype name [fields*] options* specs*) Options are expressed as sequential keywords and arguments (in an
reify
reify is a macro with the following structure: (reify options* specs*) Currently there are no options.
extend
Implementations of protocol methods can be provided using the extend construct: (extend AType AProtocol
extend-protocol
Useful when you want to provide several implementations of the same protocol all at once. Takes a single pro
extend-type
A macro that expands into an extend call. Useful when you are supplying the definitions explicitly inline, e
extenders
Returns a collection of the types explicitly extending protocol

### Code Structure

#### General

meta
Returns the metadata of obj, returns nil if there is no metadata.
with-meta
Returns an object of the same type and value as obj, with map m as its metadata.
vary-meta
Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadata.
reset-meta!
Atomically resets the metadata for a namespace/var/ref/agent/atom
alter-meta!
Atomically sets the metadata for a namespace/var/ref/agent/atom to be: (apply f its-current-meta args) f

## Environment

### Environment

#### Require / Import > General

use
Like 'require, but also refers to each lib's namespace using clojure.core/refer. Use :use in the ns macro in
require
Loads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a
import
import-list => (package-symbol class-name-symbols*) For each name in class-name-symbols, adds a mapping fro
refer-clojure
Same as (refer 'clojure.core )
refer
refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude li

### Environment

#### Code > General

*compile-files*
Set to true when compiling files, false otherwise.
*compile-path*
Specifies the directory where 'compile' will write out .class files. This directory must be in the classpath
*file*
The path of the file being evaluated, as a String. When there is no file, e.g. in the REPL, the value is no
*warn-on-reflection*
When set to true, the compiler will emit warnings when reflection is needed to resolve Java method calls or
compile
Compiles the namespace named by the symbol lib into a set of classfiles. The source for the lib must be in a
Loads Clojure code from resources in classpath. A path is interpreted as classpath-relative if it begins wit
Sequentially read and evaluate the set of forms contained in the file.
Sequentially read and evaluate the set of forms contained in the stream/file
Sequentially read and evaluate the set of forms contained in the string
Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. str
Reads one object from the string s. Optionally include reader options, as specified in read. Note that re
gen-class
When compiling, generates compiled bytecode for a class with the given package-qualified :name (which, as al
gen-interface
When compiling, generates compiled bytecode for an interface with the given package-qualified :name (which,
Returns a sorted set of symbols naming the currently loaded libs
test
test [v] finds fn at key :test in var metadata and calls it, presuming failure will throw exception

### Environment

#### IO > General

*in*
A java.io.Reader object representing standard input for read operations. Defaults to System/in, wrapped in
*out*
A java.io.Writer object representing standard output for print operations. Defaults to System/out, wrapped
*err*
A java.io.Writer object representing standard error for print operations. Defaults to System/err, wrapped i
print
Prints the object(s) to the output stream that is the current value of *out*. print and println produce out
printf
Prints formatted output, as per format
println
Same as print followed by (newline)
pr
Prints the object(s) to the output stream that is the current value of *out*. Prints the object(s), separat
prn
Same as pr followed by (newline). Observes *flush-on-newline*
print-str
print to a string, returning it
println-str
println to a string, returning it
pr-str
pr to a string, returning it
prn-str
prn to a string, returning it
newline
Writes a platform-specific newline to *out*
flush
Flushes the output stream that is the current value of *out*
Reads the next line from stream that is the current value of *in* .
slurp
Opens a reader on f and reads all its contents, returning a string. See clojure.java.io/reader for a complet
spit
Opposite of slurp. Opens f with writer, writes content, then closes f. Options passed to clojure.java.io/wr
with-in-str
Evaluates body in a context in which *in* is bound to a fresh StringReader initialized with the string s.
with-out-str
Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by
with-open
bindings => [name init ...] Evaluates body in a try expression with names bound to the values of the init

### Environment

#### REPL > General

*1
bound in a repl thread to the most recent value printed
*2
bound in a repl thread to the second most recent value printed
*3
bound in a repl thread to the third most recent value printed
*e
bound in a repl thread to the most recent exception caught by the repl
*print-dup*
When set to logical true, objects will be printed in a way that preserves their type when read in later.
*print-length*
*print-length* controls how many items of each collection the printer will print. If it is bound to logical
*print-level*
*print-level* controls how many levels deep the printer will print nested objects. If it is bound to logical
*print-meta*
If set to logical true, when printing an object, its metadata will also be printed in a form that can be rea
When set to logical false, strings and characters will be printed with non-alphanumeric characters converted

### Environment

#### Misc > General

*clojure-version*
The version info for Clojure core, as a map containing :major :minor :incremental and :qualifier keys. Feat
clojure-version
Returns clojure version as a printable string.
*command-line-args*
A sequence of the supplied command line arguments, or nil if none were supplied
time
Evaluates expr and prints the time it took. Returns the value of expr.