Clojure

API Reference

clojure.core

->

r

->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.

->>

r

->>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.

..

r

..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.

==

r

==functionUsage:(== x)(== x y)(== x y & more)Returns non-nil if nums all have the equivalent value (type-independent), otherwise false

A

accessor

r

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

r

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.

l

agent

r

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

r

agetfunctionUsage:(aget array idx)(aget array idx & idx)Returns the value at the index/indices. Works on Java arrays of all types.

alength

r

alengthfunctionUsage: (alength array)Returns the length of the Java array. Works on arrays of all types.

alter

r

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

r

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

r

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

r

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

r

array-mapfunctionUsage:(array-map)(array-map & keyvals)Constructs an array-map

assoc

r

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

r

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?

r

associative?functionUsage:(associative? coll)Returns true if coll implements Associative

atom

r

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

r

basesfunctionUsage:(bases c)Returns the immediate superclass and direct interfaces of c, if any

binding

r

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

r

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

r

butlastfunctionUsage:(butlast coll)Return a seq of all but the last item in coll, in linear time

C

comp

r

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

r

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

r

(case input :enter (assoc game :uis [(->UI :win)]) :backspace (assoc game :uis [(->UI :lose)]) \q (assoc game :uis []) game))

compile

r

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

r

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

r

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

r

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

r

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

r

consfunctionUsage:(cons x seq)returns a new seq where x is the first element and seq is the rest.

constantly

r

constantlyfunctionUsage:(constantly x)Returns a function that takes any number of arguments and returns x.

contains?

r

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

r

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

r

cyclefunctionUsage: (cycle coll)Returns a lazy (infinite!) sequence of repititions of the items in coll.

D

defmacro

r

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

r

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

r

(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

r

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?

r

delay?functionUsage: (delay? x)returns true if x is a Delay created with delay

deref

r

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

r

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

r

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

r

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

r

distinctfunctionUsage:(distinct coll)Returns a lazy sequence of the elements of coll with duplicates removed.

distinct?

r

distinct?functionUsage:(distinct? x)(distinct? x y)(distinct? x y & more)Returns true if no two of the argumenst are =

doall

r

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

r

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

r

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

r

dotimesmacroUsage: (dotimes bindings & body)bindings => name nRepeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1.

doto

r

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

r

dropfunctionUsage: (drop n coll)Returns a lazy sequence of all but the first n items in coll.

drop-last

r

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

r

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

r

emptyfunctionUsage:(empty coll)Returns an empty collection of the same category as coll, or nil

empty?

r

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

r

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

r

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?

r

every?functionUsage:(every? pred coll)Returns true if (pred x) is logical true for every x in coll, else false.

F

ffirst

r

ffirstfunctionUsage:(ffirst x)Same as (first (first x))

filter

r

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

r

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

r

findfunctionUsage:(find map key)Returns the map entry for key, or nil if key not present

first

r

firstfunctionUsage:(first coll)Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.

flatten

r

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

r

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

r

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

r

forcefunctionUsage:(force x)If x is a Delay, returns the (possibly cached) value of its expression, else returns x

format

r

formatfunctionUsage:(format fmt & args)Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax

frequencies

r

frequenciesfunctionUsage:(frequencies coll)Returns a map from distinct items in coll to the number of times they appear.

future

r

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

r

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

r

future-cancelfunctionUsage:(future-cancel f)Cancels the future, if possible.

future-done?

r

future-done?functionUsage:(future-done? f)Returns true if future f is done

future-cancelled?

r

future-cancelled?functionUsage:(future-cancelled? f)Returns true if future f is cancelled

G

get

r

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

r

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

r

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

r

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

r

hash-mapfunctionUsage:(hash-map)(hash-map & keyvals)keyval => key valReturns a new hash map with supplied mappings.

I

if-let

r

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

r

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

r

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

r

interposefunctionUsage:(interpose sep col)Returns a lazy seq of the elements of coll seperated by sep

into

r

intofunctionUsage:(into to from)Returns a new coll consisting of to-coll with all of the items of from-coll conjoined.

iterate

r

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

r

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

r

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

r

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

r

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

r

keyfunctionUsage:(key e)Returns the key of the map entry.

keys

r

keysfunctionUsage:(keys map)Reurns a sequence of the map's keys.

L

last

r

lastfunctionUsage:(last coll)Return the last item in coll, in linear time

lazy-cat

r

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

r

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

r

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

r

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

r

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

r

listfunctionUsage:(list & items)Creates a new list containing the items

list*

r

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

r

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

r

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

r

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

r

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

r

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

r

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

r

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

r

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?

r

not-every?functionUsage:(not-every? pred coll)Returns false if (pred x) is logical true for every x in coll, else true.

not-any?

r

not-any?functionUsage:(not-any? pred coll)Returns false if (pred x) if logical true for any x in coll, else true.

nnext

r

nnextfunctionUsage:(nnext x)Same as (next (next x))

nfirst

r

nfirstfunctionUsage:(nfirst x)Same as (next (first x))

next

r

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

r

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

r

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

r

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

r

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

r

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

r

pcallsfunctionUsage:(pcalls & fns)Executes the no-arg fns in parallel, returning a lazy sequence of their values.

peek

r

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!

r

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

r

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

r

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

r

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

r

randfunctionUsage:(rand)(rand n)Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive).

rand-int

r

rand-intfunctionUsage:(rand-int n)Returns a random integer between 0 (inclusive) and n (exclusive).

rand-nth

r

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

r

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

r

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

r

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

r

re-matcherfunctionUsage:(re-matcher re s)Returns an instance of java.util.regex.Matcher, for use, e.g. in re-find.

re-matches

r

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

r

re-patternfunctionUsage:(re-pattern s)Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.

re-seq

r

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

r

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

r

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

r

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

r

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

r

ref-setfunctionUsage: (ref-set ref val)Must be called in a transaction. Sets the value of ref. Returns val.

reify

r

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

r

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

r

repeatfunctionUsage:(repeat x)(repeat n x)Returns a lazy (infinite!, or length n if supplied) sequence of xs.

repeatedly

r

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

r

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

r

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!

r

reset!functionUsage:(reset! atom newval)Sets the value of atom to newval without regard for the current value. Returns newval.

rest

r

restfunctionUsage:(rest coll)Returns a possibly empty seq of the items after the first. Calls seq on its argument.

reverse

r

reversefunctionUsage:(reverse coll)Returnss a seq of the items in coll in reverse order. Not lazy.

S

satisfies?

r

satisfies?functionUsage:(satisfies? protocol x)Returns true if x satisfies the protocol

second

r

secondfunctionUsage:(second x)Same as (first (next x))

select-keys

r

select-keysfunctionUsage:(select-keys map keyseq)Returns a map containing only those entries in map whose key is in keys

shuffle

r

shufflefunctionUsage:(shuffle coll)Return a random permutation of coll

some

r

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

r

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

r

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

r

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

r

sorted-mapfunctionUsage:(sorted-map & keyvals)keyval => key valReturns a new sorted map with supplied mappings

split-at

r

split-atfunctionUsage:(split-at n coll)Returns a vector of [(take n coll) (drop n coll)]

split-with

r

split-withfunctionUsage:(split-with pred coll)Returns a vector of [(take-while pred coll) (drop-while pred coll)]

subvec

r

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

r

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

r

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

r

take-nthfunctionUsage:(take-nth n coll)Returns a lazy seq of every nth item in coll.

take-while

r

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

r

distinctfunctionUsage:(distinct coll)Returns a lazy sequence of the elements of coll with duplicates removed.

use

r

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

r

valfunctionUsage:(val e)Returns the value in the map entry

vals

r

valsfunctionUsage:(vals map)Returns a sequence of the map's values.

vec

r

vecfunctionUsage:(vec coll)Creates a new vector containing the contents of coll.

vector

r

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

r

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

r

whenmacroUsage:(when test & body)Evaluates test. If logical true, evaluates body in an implicit do.

when-first

r

when-firstmacroUsage:(when-first bindings & body)bindings => x xsSame as (when (seq xs) (let [x (first xs)] body))

when-let

r

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

r

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

r

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

r

zipmapfunctionUsage:(zipmap keys vals)Returns a map with the keys mapped to the corresponding vals.

special forms

def

r

(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

r

(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

l

cond

l

condp

l

if-let

l

if-not

l

when

l

when-first

l

when-let

l

Iteration

butlast

l

cycle

l

distinct

l

doseq

l

dotimes

l

for

l

loop

l

map

l

while

l

Function Composition

comp

l

every-pred

l

fnil

l

juxt

l

memoize

l

partial

l

Data Modeling

STM

add-watch

l

agent

l

alter

l

atom

l

delay

l

deref

l

ensure

l

force

l

future

l

future-call

l

persistent!

l

promise

l

ref

l

ref-set

l

Data Structure Manipulation

Querying

contains?

l

count

l

get

l

get-in

l

group-by

l

keep

l

keep-indexed

l

key

l

keys

l

last

l

next

l

nfirst

l

nth

l

peek

l

rest

l

second

l

select-keys

l

some

l

take

l

take-last

l

vals

l

Deriving

assoc

l

assoc-in

l

conj

l

disj

l

dissoc

l

into

l

merge

l

merge-with

l

partition

l

partition-all

l

partition-by

l

reduce

l

reduce-kv

l

reverse

l

replace

l

shuffle

l

split-at

l

split-with

l

subvec

l

update-in

l

vector

l

zipmap

l

lazy-seq

l

sort

l

sort-by

l

lazy-cat

l

hash-map

l

list

l

list*

l

pop

l

vec

l

Classes

reify

l

satisfies?

l