Clojure
API Reference
clojure.core
->
->macroUsage:(-> x)(-> x form)(-> x form & more)Threads the expr through the forms. Inserts x as the second item in the fisrt form, making a list of it if it is not alist already. If there are more forms, inserts the first form as thesecond item in second form, etc.
->>
->>macroUsage;(->> x form)(->> x form & more)Threads the expr through the forms. Inserts x as the last item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the last item in the second form, etc.
..
..macroUsage:(.. x form)(.. x form & more)form => fieldName-symbol or instanceMethodName-symbol args*)Expands into a member access (.) of the first member on the first argument, followed by the next member on the result, etc. For instance:(.. System (getProperties) (get "os.name))expands to:(. (. System (getProperties)) (get "os.name"))but is easier to write, read, and understand.
==
==functionUsage:(== x)(== x y)(== x y & more)Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
A
accessor
accessorfunctionUsage:(accessor s key)Returns a fn that, given an instance of a structmap with the basis, returns the value at the key. The key must be in the basis. The returned function should be (slightly) more efficient than using get, but such use of accessors should be limited to known performance-critical areas.
add-watch
add-watchfunctionUsage:(add-watch reference key fn)Alpha - subject to change.Adds a watch function to an agent/atom/var/ref reference. The watch fn must be a fn of args: a key, the reference, its old-state, its new-state. Whenever the reference's state might have been changed, any registered watches will have their functions called. The watch fn will be called synchronously, on the agent's htread if an agent, before any pending sends if agent or ref. Note that an atom's or ref's state may have changed again prior to the fn call, so use old/new-state rather than derefing the reference. Note also that watch fns may be called from multiple threads simultaneously. Var watchers are triggered only by root binding changes, not thread-local set!s. Keys must be unique per reference, and can be used to remove the watch with remove-watch, but are otherwise considered opaque by the watch mechanism.
lagent
agentfunctionUsage:(agent state & options)Creates and returns an agent with an initial value of state and zero or more options (in any order)::meta metadata-map:validator validate-fn:error-handler handler-fn:error-mode mode-keywordIf metadata-map is supplied, it will become the metadata on the agent. validate-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an exception. handler-fn rejects a new state -- see set-error-hanler! for details. The mode-keyword may be either :continue (the default if an error-handler is given) or :fail (the default if no error-handler is given) -- see set-error-mode! for details.
aget
agetfunctionUsage:(aget array idx)(aget array idx & idx)Returns the value at the index/indices. Works on Java arrays of all types.
alength
alengthfunctionUsage: (alength array)Returns the length of the Java array. Works on arrays of all types.
alter
alterfunctionUsage:(alter ref fun & args)Must be called in a transaction. Sets the in-transaction-value of ref to:(apply fun in-transaction-value-of-ref args)and return the in-transaction-value of ref.
amap
amapmacroUsage:(amap a idx ret expr)Maps an expression across an array a, using an index named idx, and return value named ret, initialized to a clone of a, then setting each element of ret to the evaluation of expr, returning the new array ret.
apply
applyfunctionUsage:(apply f args)(apply f x args)(apply f x y args)(apply f x y z args)(apply f a b c d & args)Applies fn f to the argument list formed by prepending intervening arguments to args.
areduce
areducemacroUsage:(areduce a idx ret init exp)Reduces an expression across an array a, using an index named idx, and return value named ret, initialized to init, setting ret to the evaluation of expr at each step, returning ret.
array-map
array-mapfunctionUsage:(array-map)(array-map & keyvals)Constructs an array-map
assoc
assocfunctionUsage: (assoc map key val)(assoc may key val & kvs)assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val at index. Note - index must be <= (count vector).
assoc-in
assoc-infunctionUsage:(assoc-in m [k & ks] v)Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created.
associative?
associative?functionUsage:(associative? coll)Returns true if coll implements Associative
atom
atomfunctionUsage:(atom x)(atom x & options)Creates and returns an Atom with an initial value of x and zero or more options (in any order)::meta metadata-map:validator validate-fnIf metadata-map is supplied, it will become the metadata on the atom. validate-fn must be nil or a side-effect-free- fn of one argument, which will be passed the intended new state on any state change. If the new state change is unacceptable, the validate-fn should return false or throw an exception.
B
bases
basesfunctionUsage:(bases c)Returns the immediate superclass and direct interfaces of c, if any
binding
bindingmacroUsage:(binding bindings & body)binding => var-symbol init-exprCreates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before. The new bindings are made in parallel (unlike let); all init-exprs are evaluated before the vars are bound to their new values.(Like a let but bindings are done in parallel?)
bound-fn
bound-fnmacroUsage:(bound-fn & fntail)Returns a function defined by the given fntail, which will install the same bindings in effect as in the thread at the time bound-fn was called. This may be used to define a helper function which runs on a different thread, but needs the same bindings in place.
butlast
butlastfunctionUsage:(butlast coll)Return a seq of all but the last item in coll, in linear time
C
comp
compfunctionUsage:(comp)(comp f)(comp f g)(comp f g h)(comp f1 f2 f3 & fs)Takes a set of functions and returns a fn that is the composition of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc.
case
casemacroUsage:(case e & clauses)Takes an expression, and a set of clauses.Each clause can tae the form of either:test-constant result-expr(test-constant1 ... test-constantN) result-exprThe test-constants are not evaluated. They must be compile-time literals, and need not be quoted. If the expression is equal to a test-constant, the corresponding result-expr is returned. A single default expression can follow the clausses, and its value will be returned if no clause matches. If no default expression is provided and no clause matches, an IllegalArgumentException is thrown.Unlike cond and condp, case does a constant-time dispatch, the clauses are not considered sequantially. All manner of constant expressions are acceptable in case, including numbers, stringss, symbols, keywords, and (Clojure) composites thereof. Note that since lists are used to group multiple constants that map to the same expression, a vector can be used to match a list if needed. The test-constants need not be all of the same type.
example
(case input :enter (assoc game :uis [(->UI :win)]) :backspace (assoc game :uis [(->UI :lose)]) \q (assoc game :uis []) game))
compile
compilefunctionUsage(compile lib)Compiles the namespace named by the symbol lib into a set of classfiles. The source for the lib must be in a proper classpath-relative directory. The output files will go into the directory specified by *compile-path*, and that directory too must be in the classpath.
concat
concatfunctionUsage:(concat)(concat x)(concat x y)(concat x y & zs)Returns a lazy seq representing the concatenation of the elements in the supplied colls
cond
condmacroUsage:(cond & clauses)Takes a set of test/expr pairs. It evaluates each test one at a time. If a test returns logical true, cond evaluates and returns the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. (cond) returns nil.
condp
condpmacroUsage:(condp pred expr & clauses)Takes a binary predicate, an expression, and a set of clauses.Each clause can take the form of either:test-expr result-exprtest-expr :>> result-fnNote :>> is an ordinary keyword.For each clause, (pred test-expr expr) is evaluated. If it returns logical true, the clause is a match. If a binary clause matches, the result-expr is returned, if a ternary clause matches, its result-fn, which must be a unary function, is called with the result of the predicate as its argument, the result of that call being the return value of condp. A single default expression can follow the clauses, and its value will be returned if no clause matches. If no default expression in provided and no clause matches, an IllegalArgumentException is thrown.
conj
conjfunctionUsage:(conj coll x)(conj coll x & xs)conj[oin]. Returns a new collection with xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type.
cons
consfunctionUsage:(cons x seq)returns a new seq where x is the first element and seq is the rest.
constantly
constantlyfunctionUsage:(constantly x)Returns a function that takes any number of arguments and returns x.
contains?
contains?functionUsage:(contains? coll key)Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'.
count
countfunctionUsage:(count coll)Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps.
cycle
cyclefunctionUsage: (cycle coll)Returns a lazy (infinite!) sequence of repititions of the items in coll.
D
defmacro
defmacromacroUsage:(defmacro name doc-string? attr-map? [params*] body)(defmacro name doc-string? attr-map? ([params*] body) + attr-map?)Like defn, but the resulting function name is declared as a macro ad ill be used as a macro by the compiler when it is called.
defmulti
defmultimacroUsage:(defmulti name docstring? attr-map? dispatch-fn & options)Creates a new multimethod with the associated dispatch function. The docstring and attributes-map are optional.Options are key-value pairs and may be one of::default the default dispatch value, defaults to :default:hierarchy the isa? hierarchy to use for dispatching defaults to the global hierarchy
example
(defmulti process-input (fn [game input] (:kind (last (:uis game)))))(defmethod process-input :start [game input] (reset-game game))(defmethod process-input :win [game input] (if (= input :escape) (assoc game :uis []) (assoc game :uis [(->UI :start)])))
delay
delaymacroUsage:(delay & body)Takes a body of expressions and yields a Delay object that will invoke the body only the first time it is forced (with force or deref/@), and will cache the result and return it on all subsequent force calls. See also - realized?
delay?
delay?functionUsage: (delay? x)returns true if x is a Delay created with delay
deref
dereffunctionUsage:(deref ref)(deref ref timeout-ms timeout-val)Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction returns the in-transaction-value of ref, else returns the most-recently-committed value of ref. When applied to a var, agent, or atom, returns its current state. When applied to a delay, forces it if not already forced. When applied to a future, will block if computation not complete. When applied to a promise, will bolck until a value is delivered. The variant taking a timeout can be used for blocking references (futures and promises), and will return timeout-val if the timeout (in milliseconds) is reached before a value is available. See also - realized?.
derive
derivefunctionUsage:(derive tag parent)(derive h tag parent)Establishes a parent/child relationship between parent and tag. Parent must be a namespace-qualified symbol or keyword and child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy.
disj
disjfunctionUsage:(disj set)(disj set key)(disj set key & ks)disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s).
dissoc
dissocfunctionUsage:(dissoc map)(dissoc map key)(dissoc map key & ks)dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s).
distinct
distinctfunctionUsage:(distinct coll)Returns a lazy sequence of the elements of coll with duplicates removed.
distinct?
distinct?functionUsage:(distinct? x)(distinct? x y)(distinct? x y & more)Returns true if no two of the argumenst are =
doall
doallfunctionUsage:(doall coll)(doall n coll)When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time.
dorun
dorunfunctionUsage:(dorun coll)(dorun n coll)When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does NOT retain the head and returns nil.
doseq
doseqmacroUsage:(doseq seq-exprs & body)Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by "for". Does not retain the head of the sequence. Returns nil.
dotimes
dotimesmacroUsage: (dotimes bindings & body)bindings => name nRepeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1.
doto
dotomacroUsage:(doto x & forms)Evaluates x then calls all of the methods and functions with the value of x supplied at the front of the given arguments. The forms are evaluated in order. Returns x.(doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2))
drop
dropfunctionUsage: (drop n coll)Returns a lazy sequence of all but the first n items in coll.
drop-last
drop-lastfunctionUsage:(drop-last s)(drop-last n s)Return a lazy sequence of all but the last n (default 1) items in coll
drop-while
drop-whilefunctionUsage: (drop-while pred coll)Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns logical false.
E
empty
emptyfunctionUsage:(empty coll)Returns an empty collection of the same category as coll, or nil
empty?
empty?functionUsage:(empty? coll)Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not (empty? x))
ensure
ensurefunctionUsage:(ensure ref)Must be called in a transaction. Protects the ref from modification by other transactions. Returns the in-transaction-value of ref. Allows for more concurrency than (ref-set ref @ref)
every-pred
every-predfunctionUsage:(every-pred p)(every-pred p1 p2)(every-pred p1 p2 p3)(every-pred p1 p2 p3 & ps)Takes a set of predicates and returns a function f that returns true if all of its composing predicates returns a logical true value against all of its arguments, else it returns false. Note that f is short-circuiting in that it will stop execution on the first argument that triggers a logical false result against the original predicates.
every?
every?functionUsage:(every? pred coll)Returns true if (pred x) is logical true for every x in coll, else false.
F
ffirst
ffirstfunctionUsage:(ffirst x)Same as (first (first x))
filter
filterfunctionUsage:(filter pred coll)Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects.
filterv
filtervfunctionUsage:(filterv pred coll)Returns a vector of the items in coll for which (pred item) returns true. pred must be free fo side-effects.
find
findfunctionUsage:(find map key)Returns the map entry for key, or nil if key not present
first
firstfunctionUsage:(first coll)Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.
flatten
flattenfunctionUsage:(flatten x)Takes any nested comination of sequential things (lists, vectors, etc.) and returns their contents as a single, flat, sequence.(flatten nil) returns an empty sequence.
fnil
fnilfunctionUsage:(fnil f x)(fnil f x y)(fnil f x y z)Takes a function f, and returns a function that calls f, replacing a nil first argument to f with the supplied value x. Higher arity versions can replace arguments in the second and third positions (y, z). Note that the function f can take any number of argumetns, not just the one(s) being nil-patched.
for
formacroUsage:(for seq-exprs body-expr)List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms. Supported modifiers are: :let [binding-form expr ...], :while test, :when test.(take 100 (for [x (range 1000000000) y (range 10000000) :while (< y x)] [x y]))
force
forcefunctionUsage:(force x)If x is a Delay, returns the (possibly cached) value of its expression, else returns x
format
formatfunctionUsage:(format fmt & args)Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax
frequencies
frequenciesfunctionUsage:(frequencies coll)Returns a map from distinct items in coll to the number of times they appear.
future
futuremacroUsage:(future & body)Takes a body of expressions and yields a future object that will invoke the body in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block, unless the variant of deref with timeout is used. See also - realized?.
future-call
future-callfunctionUsage: (future-call f)Takes a function of no args and yields a future object that will invoke the function in another thread, and will cache the result and return it on all subsequent calls to deref/@. If the computation has not yet finished, calls to deref/@ will block, unless the variant of deref with timeout is used. See also - realized?.
future-cancel
future-cancelfunctionUsage:(future-cancel f)Cancels the future, if possible.
future-done?
future-done?functionUsage:(future-done? f)Returns true if future f is done
future-cancelled?
future-cancelled?functionUsage:(future-cancelled? f)Returns true if future f is cancelled
G
get
getfunctionUsage:(get map key)(get map keye not-found)Returns the value mapped to key, not-found or nil if key not present.
get-in
get-infunctionUsage:(get-in m ks)(get-in m ks not-found)Returns the value in a nested associative structure, where ks is a sequence of keys. Returns nil if the key is not present, or the not-fonud value if supplied.
get-method
get-methodfunctionUsage:(get-method multifn dispatch-val)Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, or nil if none apply and no default
group-by
group-byfunctionUsage:(group-by f coll)Returns a map of the elements of coll keyed by the result of f on each element. The value at each key will be a vector of the corresponding elements, in the order they appeared in coll.
H
hash-map
hash-mapfunctionUsage:(hash-map)(hash-map & keyvals)keyval => key valReturns a new hash map with supplied mappings.
I
if-let
if-letmacroUsage:(if-let bindings then)(if-let bindings then else & oldform)bindings => binding-form testIf test is true, evaluates then with binding-form bound to the value of the test, if not yields else
if-not
if-notmacroUsage:(if-not test then)(if-not test then else)Evaluates test. If logical false, evaluates and returns then expr, otherwise else expr, if supplied, else nil.
import
importmacroUsage:(import & import-symbols-or-lists)import-list => (package-symbol class-name-symbols*)For each name in class-name-symbols, adds a mapping from name to the class named by package.name to the current namespace. Use :import in the ns macro in preference to calling this directly.
interpose
interposefunctionUsage:(interpose sep col)Returns a lazy seq of the elements of coll seperated by sep
into
intofunctionUsage:(into to from)Returns a new coll consisting of to-coll with all of the items of from-coll conjoined.
iterate
iteratefunctionUsage:(iterate f x)Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects
iterate-seq
iterator-seqfunctionUsage:(iterator-seq iter)Returns a seq on a java.util.Iterator. note that most collections provided iterators implement Iterable and thus support seq directly.
J
juxt
juxtfuntionnUsage:(juxt f)(juxt f g)(juxt f g h)(juxt f g h & fs)Takes a set of functions and returns a fn that is the juxtaposition of those fns. The returned fn takes a variable number of args, and returns a vector containing the result of applying each fn to the args (left-to-right).((juxt a b c) x) => [(a x) (b x) (c x)]
K
keep
keepfunctionUsage: (keep f coll)Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects.
keep-indexed
keep-indexedfunctionUsage:(keep-indexed f coll)Returns a lazy sequence of the non-nil results of (f index item). Note, this means false return values will be included. f must be free of side-effects.
key
keyfunctionUsage:(key e)Returns the key of the map entry.
keys
keysfunctionUsage:(keys map)Reurns a sequence of the map's keys.
L
last
lastfunctionUsage:(last coll)Return the last item in coll, in linear time
lazy-cat
lazy-catmacroUsage:(lazy-cat & colls)Expands to code which yields a lazy sequence of the concatenation of the supplied colls. Each coll expr is not evaluated until it is needed.(lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))
lazy-seq
lazy-seqmacroUsage: (lazy-seq & body)Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent seq calls. See also - realized?
let
letmacroUsage:(let bindings & body)bindings => binding-form init-exprEvaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein.
letfn
letfnmacroUsage:(letfn fnspecs & body)fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)Takes a vector of function specs and a body, and generates a set of bindings of functions to their names. All of the names are available in all of the definitions of the functions, as well as the body.
line-seq
line-seqfunctionUsage:(line-seq rdr)Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader
list
listfunctionUsage:(list & items)Creates a new list containing the items
list*
list*fuctionUsage:(list* args)(list* a args)(list* a b args)(list* a b c args)(list* a b c d & more)Creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence.
loop
loopmacroUsage:(loop bindings & body)Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein. Acts as a recur target.
M
map
mapfunctionUsage:(map f coll)(map f c1 c2)(map f c1 c2 c3)(map f c1 c2 c3 & colls)Returns a lazy sequence consisting of the result of applying f to the set of first items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments.
map-indexed
map-indexedfunctionUsage:(map-indexed f coll)Returns a lazy sequence consisting of the result of applying f to 0 and the first item of coll, followed by applying f to 1 and the second item in coll, etc, until coll is exhausted. Thus function f should accept 2 arguments, index and item.
mapcat
mapcatfunctionUsage:(mapcat f & colls)Returns the result of applying concat to the result of applying map to f and colls. Thus function f should return a collection.
mapv
mapvfunctionUsage:(mapv f coll)(mapv f c1 c2)(mapv f c1 c2 c3)(mapv f c1 c2 c3 & colls)Returns a vector consisting of the result of applying f to the set of first items of each coll, followed by applying f to the set of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments.
memoize
memoizefunctionUsage:(memoize f)Returns a memoized version of a referentially transparent function. The memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use.
merge
mergefunctionUsage:(merge & maps)Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter (left-to-right) will be the mapping in the result.
merge-with
merge-withfunctionUsage:(merge-with f & maps)Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter).
N
not-every?
not-every?functionUsage:(not-every? pred coll)Returns false if (pred x) is logical true for every x in coll, else true.
not-any?
not-any?functionUsage:(not-any? pred coll)Returns false if (pred x) if logical true for any x in coll, else true.
nnext
nnextfunctionUsage:(nnext x)Same as (next (next x))
nfirst
nfirstfunctionUsage:(nfirst x)Same as (next (first x))
next
nextfunctionUsage:(next coll)Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil.
nth
nthfunctionUsage:(nth coll index)(nth coll index not-found)Returns the value at the index. get returns nil if index out of bounds, nth throws an exception unless not-fonud is supplied. nth also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences.
P
partial
partialfunctionUsage:(partial f arg1)(partial f arg1 arg2)(partial f arg1 arg2 arg3)(partial f arg1 arg2 arg3 & more)Takes a function f and fewer than normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args.
partition
partitionfunctionUsage:(partition n coll)(partition n step coll)(partition n step pad coll)Returns a lazy sequence of lists of n items each, at offsets step apart. If step is not supplied, defaults to n, i.e. the partitions do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items.
partition-all
partition-allfunctionUsage:(partition-all n coll)(partition-all n step coll)Returns a lazy sequence of lists like partition, but may include partitions with fewer than n items at the end.
partition-by
partition-byfunctionUsage:(partition-by f coll)Applies f to each value in coll, splitting it each time f returns a new value. Returns a lazy seq of partitions.
pcalls
pcallsfunctionUsage:(pcalls & fns)Executes the no-arg fns in parallel, returning a lazy sequence of their values.
peek
peekfunctionUsage:(peek coll)For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collection is empty, returns nil.
persistent!
persistent!functionUsage:(persistent! coll)Alpha - subject to change.Returns a new, persistent version of the transient collection, in constant time. The transient collection cannot be used after this call, any such use will throw an exception.
pmap
pmapfunctionUsage:(pmap f coll)(pmap f coll & colls)Like map, except f is applied in parallel. Semi-lazy in that the parallel computation stays ahead of the consumption, but doesn't realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead.
pop
popfunctionUsage:(pop coll)For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast.
promise
promisefunctionUsage:(promise)Alpha - subject to change.Returns a promise object that can be read with deref/@, and set, once only, with deliver. Calls to deref/@ prior to delivery will block, unless the variant of deref with timeout is used. All subsequent derefs will return the same delivered value without blocking. See also - realized?
R
rand
randfunctionUsage:(rand)(rand n)Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive).
rand-int
rand-intfunctionUsage:(rand-int n)Returns a random integer between 0 (inclusive) and n (exclusive).
rand-nth
rand-nthfunctionUsage:(rand-nth coll)Return a random element of the (sequential) collection. Will have the same performance characteristics as nth for the given collection.
range
rangefunctionUsage:(range)(range end)(range start end)(range start end step)Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, where start defaults to 0, step to 1, and end to infinity.
re-find
re-findfunctionUsage:(re-find m)(re-find re s)Returns the next regex match, if any, of string to pattern, using java.util.regex.Matcher.find(). Uses re-groups to return the groups.
re-groups
re-groupsfunctionUsage:(re-groups m)Returns the groups from the most recent match/find. If there are no nested groups, returns a string of the entire match. If there are nested groups, returns a vector of the groups, the first element being the entire match.
re-matcher
re-matcherfunctionUsage:(re-matcher re s)Returns an instance of java.util.regex.Matcher, for use, e.g. in re-find.
re-matches
re-matchesfunctionUsage:(re-matches re s)Returns the match, if any, of string to pattern, using java.util.regex.Matcher.matches(). Uses re-groups to return the groups.
re-pattern
re-patternfunctionUsage:(re-pattern s)Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.
re-seq
re-seqfunctionUsage:(re-seq re s)Returns a lazy sequence of successive matches of pattern in string, using java.util.regex.Matcher.find(), each such match processed with re-groups.
reduce
reducefunctionUsage:(reduce f coll)(reduce f val coll)f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the result of applying f to val and the first item in coll, then applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called.
reduce-kv
reduce-kvfunctionUsage:(reduce-kv f init coll)Reduces an associative collection. f should be a function of 3 arguments. Returns the result of applying f to init, the first key and the first value in coll, then applying f to that result and the 2nd keey and value, etc. If coll contains no entries, returns init and f is not called. Note that reduce-kv is supported on vectors, where the keys will be the ordinals.
reductions
reductionsfunctionUsage:(reductions f coll)(reductions f init coll)Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting with init.
ref
reffunctionUsage:(ref x)(ref x & options)Creates and returns a Ref with an initial value of x and zero or more options (in any order)::meta metadump-map:validator validate-fn:min-history (default 0):max-history (default 10)
ref-set
ref-setfunctionUsage: (ref-set ref val)Must be called in a transaction. Sets the value of ref. Returns val.
reify
reifymacroUsage:(reify & opts+specs)reify is a macro with the following structure:(reify options * specs*)Currently there are no options. Each spec consists of the protocol or interface name followed by zero or more method bodies:protocol-or-interface-or-Object(methodName [args+] body)*
remove
removefunctionUsage:(remove pred coll)Returns a lazy sequence of the items in coll for which (pred item) returns false. pred must be free of side-effects.
repeat
repeatfunctionUsage:(repeat x)(repeat n x)Returns a lazy (infinite!, or length n if supplied) sequence of xs.
repeatedly
repeatedlyfunctionUsage:(repeatedly f)(repeatedly n f)Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls to it.
replace
replacefunctionUsage:(replace smap coll)Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in smap replaced with the corresponding val in smap.
require
requirefunctionUsage:(require & args)Loads libs, skipping any that are already loaded. Each argument is either a libspec that identifies a lib, a prefix list that identifies multiple libs whose names share a common prefix, or a flag that modifies how all the identified libs are loaded. Use :require in the ns macro is preference to calling this directly.
reset!
reset!functionUsage:(reset! atom newval)Sets the value of atom to newval without regard for the current value. Returns newval.
rest
restfunctionUsage:(rest coll)Returns a possibly empty seq of the items after the first. Calls seq on its argument.
reverse
reversefunctionUsage:(reverse coll)Returnss a seq of the items in coll in reverse order. Not lazy.
S
satisfies?
satisfies?functionUsage:(satisfies? protocol x)Returns true if x satisfies the protocol
second
secondfunctionUsage:(second x)Same as (first (next x))
select-keys
select-keysfunctionUsage:(select-keys map keyseq)Returns a map containing only those entries in map whose key is in keys
shuffle
shufflefunctionUsage:(shuffle coll)Return a random permutation of coll
some
somefunctionUsage:(some pred coll)Returns the first logical true value of (pred x) for any x in coll, else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil:(some #{:fred} coll)
some-fn
some-fnfunctionUsage:(some-fn p)(some-fn p1 p2)(some-fn p1 p2 p3)(some-fn p1 p2 p3 & ps)Takes a set of predicates and returns a function f that returns the first logical true value returned by one of its composing predicates aganist any of its argumentns, else it returns logical false. Note that f is short-circuiting in that it will stop execution on the first argument that triggers a logical true result against the original predicates.
sort
sortfunctionUsage:(sort coll)(sort comp coll)Returns a sorted sequence of the items in coll. If no comparator is supplied, uses compare. comparator must implement java.util.Comparator.
sort-by
sort-byfunctionUsage:(sort-by keyfn coll)(sort-by keyfn comp coll)Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item). If no comparator is supplied, uses compare. comparator must implement java.util.Comparator.
sorted-map
sorted-mapfunctionUsage:(sorted-map & keyvals)keyval => key valReturns a new sorted map with supplied mappings
split-at
split-atfunctionUsage:(split-at n coll)Returns a vector of [(take n coll) (drop n coll)]
split-with
split-withfunctionUsage:(split-with pred coll)Returns a vector of [(take-while pred coll) (drop-while pred coll)]
subvec
subvecfunctionUsage:(subvec v start)(subvec v start end)Returns a persistent vector of the items in vector from start (inclusive) to end (exclusive). If end is not supplied defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structures with the original and no trimming is done.
T
take
takefunctionUsage:(take n coll)Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n.
take-last
take-lastfunctionUsage:(take-last n coll)Returns a seq of the last n items in coll. Depending on the type of coll may be no better than linear time. For vectors, see also subvec.
take-nth
take-nthfunctionUsage:(take-nth n coll)Returns a lazy seq of every nth item in coll.
take-while
take-whilefunctionUsage:(take-while pred coll)Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects.
U
update-in
distinctfunctionUsage:(distinct coll)Returns a lazy sequence of the elements of coll with duplicates removed.
use
usefunctionUsage:(use & args)Like 'require, but also refers to each lib's namespace using clojure.core/refer. Use :use in the ns macro in preference to calling this directly.'use accepts additional options in libspecs::exclude, :only, :rename
V
val
valfunctionUsage:(val e)Returns the value in the map entry
vals
valsfunctionUsage:(vals map)Returns a sequence of the map's values.
vec
vecfunctionUsage:(vec coll)Creates a new vector containing the contents of coll.
vector
vectorfunctionUsage:(vector)(vector a)(vector a b)(vector a b c)(vector a b c d)(vector a b c d & args)Creates a new vector containing the args.
vector-of
vector-offunctionUsage:(vector-of t)(vector-of t & elements)Creates a new vector of a single primitive type t, where t is one of :int :long :float :double :byte :short :char or :boolean. The resulting vector complies with the interface of vectors in general, but stores the values unboxed internally.
W
when
whenmacroUsage:(when test & body)Evaluates test. If logical true, evaluates body in an implicit do.
when-first
when-firstmacroUsage:(when-first bindings & body)bindings => x xsSame as (when (seq xs) (let [x (first xs)] body))
when-let
when-letmacroUsage:(when-let bindings & body)bindings => binding-form testWhen test is true, evaluates body with binding-form bound to the value of test.
while
whilemacroUsage:(while test & body)Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil
with-bindings
with-bindingsmacroUsage:(with-bindings binding-map & body)Takes a map of Var/value pairs. Installs for the given Vars the associated values as thread-local bindings. Then executes body. Pops the installed bindings after body was evaluated. Returns the value of body.
Z
zipmap
zipmapfunctionUsage:(zipmap keys vals)Returns a map with the keys mapped to the corresponding vals.
special forms
def
(def symbol init?)Creates and interns or locates a global var with the name of symbol and a namespace of value of the current namespace (*ns*). If init is supplied, it is evaluated, and the root binding of the var is set to the resulting value. If init is not supplied, the root binding of the var is unaffected. def always applies to the root binding, even if the var is thread-bound at the point where def is called. def yields the var itself (not its value). Throws an exception if symbol is already in the namespace and not mapped to an interned var. Since 1.3, def has allowed an optional doc-string: (def symbol doc-string? init?)Any metadata on the symbol will be evaluated, and become metadata on the var itself. There are several metadata keys that have special interpretation::private a boolean indicating the access control for the var. If this key is not present, the default access is public (e.g. as if :private false).:doc a string containing short (1-3 line) documentation for the var contents:test a fn of no args that uses assert to check various operations. he var itself will be accessibly during evaluation of a literal fn in the metadata map.:tag a symbol naming a class or a Class object that indicates the Java type of the object in the var, or its return value if the object is a fn.In addition the compiler will place the following keys on the var::file string:line int:name simple symbol:ns namespace in which var is interned:macro true if var names a macro:arglists a list of vector(s) of argument forms, as were supplied to defn
Debugging
clojure.tools.trace
Leiningen Dependency Info
[org.clojure/tools.trace "0.7.3"]
Usage
(use 'clojure.tools.trace)(trace (* 2 3)) ;; To trace a value(trace tag (* 2 3)) ;; To trace a value and assign a trace tag(deftrace fubar [x v] (+ x v)) ;; To trace a function call and its return value(trace-forms (+ 1 3) (* 5 6) (/ 1 0))(trace-ns myown.namespace) ;; To dynamically trace/untrace all fns in a name space (untrace-ns myown.namespace)(trace-vars myown.namespace/fubar) ;; To dynamically trace/untrace specific fns (untrace-vars myown.namespace/fubar)
Help
Glossary
coll - Short for collection
seq - Short of sequence
Legend
I have outstanding questions
Operates at Java level
Lazy evaluation
Program Flow
Conditionals
case
cond
condp
if-let
if-not
when
when-first
when-let
Iteration
butlast
cycle
distinct
doseq
dotimes
for
loop
map
while
Function Composition
comp
every-pred
fnil
juxt
memoize
partial
Data Modeling
STM
add-watch
agent
alter
atom
delay
deref
ensure
force
future
future-call
persistent!
promise
ref
ref-set
Data Structure Manipulation
Querying
contains?
count
get
get-in
group-by
keep
keep-indexed
key
keys
last
next
nfirst
nth
peek
rest
second
select-keys
some
take
take-last
vals
Deriving
assoc
assoc-in
conj
disj
dissoc
into
merge
merge-with
partition
partition-all
partition-by
reduce
reduce-kv
reverse
replace
shuffle
split-at
split-with
subvec
update-in
vector
zipmap
lazy-seq
sort
sort-by
lazy-cat
hash-map
list
list*
pop
vec
Classes
reify
satisfies?