API

This is documentation for all of Clojure's functions and macros, arranged alphabetically within namespace. It is generated from the source and reflects the current SVN version. All namespaces are loaded by the runtime except inspector.

clojure


(* [])

(* [x])

(* [x y])

(* [x y & more])

Returns the product of nums. (*) returns 1.


(+ [])

(+ [x])

(+ [x y])

(+ [x y & more])

Returns the sum of nums. (+) returns 0.


(- [x])

(- [x y])

(- [x y & more])

If no ys are supplied, returns the negation of x, else subtracts the ys from x and returns the result.


(-> [x form])

(-> [x form & more])

Macro

Macro. Threads the expr through the forms. Inserts x as the second 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 second item in second form, etc.


(.. [x form])

(.. [x form & more])

Macro

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.


(/ [x])

(/ [x y])

(/ [x y & more])

If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the denominators.


(< [x])

(< [x y])

(< [x y & more])

Returns non-nil if nums are in monotonically increasing order, otherwise false.


(<= [x])

(<= [x y])

(<= [x y & more])

Returns non-nil if nums are in monotonically non-decreasing order, otherwise false.


(= [x y])

Equality. Returns true if obj1 equals obj2, false if not. Same as Java obj1.equals(obj2) except it also works for nil, and compares numbers in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison.


(== [x])

(== [x y])

(== [x y & more])

Returns non-nil if nums all have the same value, otherwise false


(> [x])

(> [x y])

(> [x y & more])

Returns non-nil if nums are in monotonically decreasing order, otherwise false.


(>= [x])

(>= [x y])

(>= [x y & more])

Returns non-nil if nums are in monotonically non-increasing order, otherwise false.


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


(agent [state])

Creates and returns an agent with an initial value of state.


(agent-errors [a])

Returns a sequence of the exceptions thrown during asynchronous actions of the agent.


(aget [array idx])

(aget [array idx & idxs])

Returns the value at the index/indices. Works on Java arrays of all types.


(alength [array])

Returns the length of the Java array. Works on arrays of all types.


(all-ns [])

Returns a sequence of all namespaces.


(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 [])

(and [x])

(and [x & rest])

Macro

Evaluates exprs one at a time, from left to right. If a form returns logical false (nil or false), and returns that value and doesn't evaluate any of the other expressions, otherwise it returns the value of the last expr. (and) returns true.


(apply [f args* argseq])

Applies fn f to the argument list formed by prepending args to argseq.


(array-map [])

(array-map [& keyvals])

Constructs an array-map.


(aset [array idx val])

(aset [array idx idx2 & idxv])

Sets the value at the index/indices. Works on Java arrays of reference types. Returns val.


(aset-boolean [array idx val])

(aset-boolean [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of boolean. Returns val.


(aset-byte [array idx val])

(aset-byte [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of byte. Returns val.


(aset-char [array idx val])

(aset-char [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of char. Returns val.


(aset-double [array idx val])

(aset-double [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of double. Returns val.


(aset-float [array idx val])

(aset-float [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of float. Returns val.


(aset-int [array idx val])

(aset-int [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of int. Returns val.


(aset-long [array idx val])

(aset-long [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of long. Returns val.


(aset-short [array idx val])

(aset-short [array idx idx2 & idxv])

Sets the value at the index/indices. Works on arrays of short. Returns val.


(assert [x])

Macro

Evaluates expr and throws an exception if it does not evaluate to logical true.


(assoc [map key val])

(assoc [map 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).


(await [& agents])

Blocks the current thread (indefinitely!) until all actions dispatched thus far, from this thread or agent, to the agent(s) have occurred.


(await-for [timeout-ms & agents])

Blocks the current thread until all actions dispatched thus far (from this thread or agent) to the agents have occurred, or the timeout (in milliseconds) has elapsed. Returns nil if returning due to timeout, non-nil otherwise.


(bean [x])

Takes a Java object and returns a read-only implementation of the map abstraction based upon its JavaBean properties.


(binding [bindings & body])

Macro

binding => var-symbol init-expr Creates 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.


(bit-and [x y])

Bitwise and


(bit-not [x])

Bitwise not


(bit-or [x y])

Bitwise or


(bit-shift-left [x y])

Bitwise shift left


(bit-shift-right [x y])

Bitwise shift right


(bit-xor [x y])

Bitwise exclusive or


(boolean [x])

Coerce to boolean


(butlast [coll])

Return a sequence of all but the last item in coll, in linear time


(byte [x])

Coerce to byte


(cast [c x])

Throws a ClassCastException if x is not a c, else returns x.


(char [x])

Coerce to char


(class [x])

Returns the Class of x


(clear-agent-errors [a])

Clears any exceptions thrown during asynchronous actions of the agent, allowing subsequent actions to occur.


(comment [& body])

Macro

Ignores body, yields nil


(commute [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) At the commit point of the transaction, sets the value of ref to be: (apply fun most-recently-committed-value-of-ref args) Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. commute allows for more concurrency than ref-set.


(comp [& 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.


(comparator [pred])

Returns an implementation of java.util.Comparator based upon pred.


(complement [f])

Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value.


(concat [])

(concat [x & xs])

Returns a lazy seq representing the concatenation of the elements in x + xs.


(cond [& clauses])

Macro

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.


(conj [coll x])

conj[oin]. Returns a new collection with the x 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type.


(cons [x seq])

Returns a new seq where x is the first element and seq is the rest.


(constantly [x])

Returns a function that takes any number of arguments and returns x.


(construct-proxy [c & ctor-args])

Takes a proxy class and any arguments for its superclass ctor and creates and returns an instance of the proxy.


(contains? [map key])

Returns true if key is present, else false.


(count [coll])

Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps


(create-ns [sym])

Create a new namespace named by the symbol if one doesn't already exist, returns it or the already-existing namespace of the same name.


(create-struct [& keys])

Returns a structure basis object.


(cycle [coll])

Returns a lazy (infinite!) seq of repetitions of the items in coll.


(dec [x])

Returns a number one less than num.


(defmacro [name doc-string? attr-map? [params*] body])

(defmacro [name doc-string? attr-map? ([params*] body) + attr-map?])

Macro

Like defn, but the resulting function name is declared as a macro and will be used as a macro by the compiler when it is called.


(defmethod [multifn dispatch-val & fn-tail])

Macro

Creates and installs a new method of multimethod associated with dispatch-value.


(defmulti [name dispatch-fn])

(defmulti [name dispatch-fn default-val])

Macro

Creates a new multimethod with the associated dispatch function. If default-dispatch-val is supplied it becomes the default dispatch value of the multimethod, otherwise the default dispatch value is :default.


(defn [name doc-string? attr-map? [params*] body])

(defn [name doc-string? attr-map? ([params*] body) + attr-map?])

Macro

Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-string or attrs added to the var metadata


(defn- [name & decls])

Macro

same as defn, yielding non-public def


(defstruct [name & keys])

Macro

Same as (def name (create-struct keys...))


(deref [ref])

Also reader macro: @ref/@agent Within a transaction, returns the in-transaction-value of ref, else returns the most-recently-committed value of ref. When applied to an agent, returns its current state.


(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 [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 [coll])

Returns a lazy sequence of the elements of coll with duplicates removed


(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 rests of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time.


(doc [varname])

Macro

Prints documentation for the var named by varname


(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 rests of the seq, does not retain the head and returns nil.


(doseq [item list & body])

Macro

Repeatedly executes body (presumably for side-effects) with binding-form bound to successive items from coll. Does not retain the head of the sequence. Returns nil.


(dosync [& exprs])

Macro

Runs the exprs (in an implicit do) in a transaction that encompasses exprs and any nested calls. Starts a transaction if none is already running on this thread. Any uncaught exception will abort the transaction and flow out of dosync. The exprs may be run more than once, but any effects on Refs will be atomic.


(dotimes [i n & body])

Macro

Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1.


(doto [x & members])

Macro

Evaluates x then calls all of the methods with the supplied arguments in succession on the resulting object, returning it. (doto (new java.util.HashMap) (put "a" 1) (put "b" 2))


(double [x])

Coerce to double


(drop [n coll])

Returns a lazy seq of all but the first n items in coll.


(drop-while [pred coll])

Returns a lazy seq of the items in coll starting from the first item for which (pred item) returns nil.


(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)


(eval [form])

Evaluates the form data structure (not text!) and returns the result.


(every? [pred coll])

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


(false? [x])

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


(ffirst [x])

Same as (first (first x))


(file-seq [dir])

A tree seq on java.io.Files


(filter [pred coll])

Returns a lazy seq of the items in coll for which (pred item) returns true.


(find [map key])

Returns the map entry for key, or nil if key not present.


(find-doc [re-string])

Prints documentation for any var whose documentation or name contains a match for re-string


(find-ns [sym])

Returns the namespace named by the symbol or nil if it doesn't exist.


(find-var [sym])

Returns the global var named by the namespace-qualified symbol, or nil if no var with that name.


(first [coll])

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


(float [x])

Coerce to float


(flush [])

Flushes the output stream that is the current value of *out*


(fn [& sigs])

Macro

(fn name? [params* ] exprs*) (fn name? ([params* ] exprs*)+) params => positional-params* , or positional-params* & rest-param positional-param => binding-form rest-param => binding-form name => symbol Defines a function


(fnseq [first restfn])

Returns a seq object whose first is first and whose rest is the value produced by calling restfn with no arguments. restfn will be called at most once per step in the sequence, e.g. calling rest repeatedly on the head of the seq calls restfn once - the value it yields is cached.


(for [seq-expr expr])

(for [seq-exprs filter-expr expr])

Macro

List comprehension. Takes one or more binding-form/collection-expr pairs, an optional filtering (where) expression, 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.


(frest [x])

Same as (first (rest x))


(gensym [])

(gensym [prefix-string])

Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix# where # is some unique number. If prefix is not supplied, the prefix is 'G'.


(get [map key])

(get [map key not-found])

Returns the value mapped to key, not-found or nil if key not present.


(get-proxy-class [& bases])

Takes an optional single class followed by zero or more interfaces. If not supplied class defaults to Object. Creates an returns an instance of a proxy class derived from the supplied classes. The resulting value is cached and used for any subsequent requests for the same class set. Returns a Class object.


(hash-map [])

(hash-map [& keyvals])

keyval => key val Returns a new hash map with supplied mappings.


(hash-set [])

(hash-set [& keys])

Returns a new hash set with supplied keys.


(identical? [x y])

Tests if 2 arguments are the same object


(identity [x])

Returns its argument.


(if-let [name test then else])

Macro

Same as (let [name test] (if name then else))


(import [& import-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.


(in-ns [name])

Sets *ns* to the namespace named by the symbol, creating it if needed.


(inc [x])

Returns a number one greater than num.


(instance? [c x])

Evaluates x and tests if it is an instance of the class c. Returns true or false


(int [x])

Coerce to int


(interleave [& colls])

Returns a lazy seq of the first item in each coll, then the second etc.


(into [to from])

Returns a new coll consisting of to-coll with all of the items of from-coll conjoined.


(into-array [aseq])

Returns an array of the type of the first element in coll, containing the contents of coll, which must be of a compatible type.


(iterate [f x])

Returns a lazy seq of x, (f x), (f (f x)) etc.


(key [e])

Returns the key of the map entry.


(keys [map])

Returns a sequence of the map's keys.


(keyword [name])

(keyword [ns name])

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


(keyword? [x])

Return true if x is a Keyword


(last [coll])

Return the last item in coll, in linear time


(lazy-cat [coll])

(lazy-cat [coll & colls])

Macro

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-cons [first-expr & rest-expr])

Macro

Expands to code which produces a seq object whose first is first-expr (evaluated) and whose rest is rest-expr, which is not evaluated until rest is called. rest-expr will be evaluated at most once per step in the sequence, e.g. calling rest repeatedly on the head of the seq evaluates rest-expr once - the value it yields is cached.


(let [bindings & body])

Macro

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.


(line-seq [rdr])

Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader.


(list [& items])

Creates a new list containing the items.


(list* [item & more])

Creates a new list containing the item prepended to more.


(load [rdr])

Sequentially read and evaluate the set of forms contained in the stream/file


(load-file [name])

Sequentially read and evaluate the set of forms contained in the file.


(locking [x & body])

Macro

Executes exprs in an implicit do, while holding the monitor of x. Will release the monitor of x in all circumstances.


(long [x])

Coerce to long


(loop [bindings & body])

Macro

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.


(macroexpand [form])

Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note neither macroexpand-1 nor macroexpand expand macros in subforms.


(macroexpand-1 [form])

If form represents a macro form, returns its expansion, else returns form.


(make-array [type len])

(make-array [type dim & more-dims])

Creates and returns an array of instances of the specified class of the specified dimension(s). Note that a class object is required. Class objects can be obtained by using their imported or fully-qualified name. Class objects for the primitive types can be obtained using, e.g., (. Integer TYPE).


(map [f coll])

(map [f coll & colls])

Returns a lazy seq 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.


(map? [x])

Return true if x implements IPersistentMap


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


(max [x])

(max [x y])

(max [x y & more])

Returns the greatest of the nums.


(max-key [k x])

(max-key [k x y])

(max-key [k x y & more])

Returns the x for which (k x), a number, is greatest.


(memfn [name & args])

Macro

Expands into code that creates a fn that expects to be passed an object and any args and calls the named instance method on the object passing the args. Use when you want to treat a Java method as a first-class fn.


(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 [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).


(meta [obj])

Returns the metadata of obj, returns nil if there is no metadata.


(min [x])

(min [x y])

(min [x y & more])

Returns the least of the nums.


(min-key [k x])

(min-key [k x y])

(min-key [k x y & more])

Returns the x for which (k x), a number, is least.


(name [x])

Returns the name String of a symbol or keyword.


(namespace [x])

Returns the namespace String of a symbol or keyword, or nil if not present.


(neg? [x])

Returns true if num is less than zero, else false


(newline [])

Writes a newline to the output stream that is the current value of *out*


(nil? [x])

Returns true if x is nil, false otherwise.


(not [x])

Returns true if x is logical false, false otherwise.


(not-any? [pred coll])

Returns false if (pred x) is logical true for any x in coll, else true.


(not-every? [pred coll])

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


(not= [x y])

Same as (not (= obj1 obj2))


(ns-imports [ns])

Returns a map of the import mappings for the namespace.


(ns-interns [ns])

Returns a map of the intern mappings for the namespace.


(ns-map [ns])

Returns a map of all the mappings for the namespace.


(ns-name [ns])

Returns the name of the namespace, a symbol.


(ns-publics [ns])

Returns a map of the public intern mappings for the namespace.


(ns-refers [ns])

Returns a map of the refer mappings for the namespace.


(ns-resolve [ns sym])

Returns the var or Class to which a symbol will be resolved in the namespace, else nil. Note that if the symbol is fully qualified, the var/Class to which it resolves need not be present in the namespace.


(ns-unmap [ns sym])

Removes the mappings for the symbol from the namespace.


(nth [coll index])

Returns the value at the index. get returns nil if index out of bounds, nth throws an exception. nth also works for strings, Java arrays and Lists, and, in O(n) time, for sequences.


(nthrest [coll n])

Returns the nth rest of coll, (seq coll) when n is 0.


(or [])

(or [x])

(or [x & rest])

Macro

Evaluates exprs one at a time, from left to right. If a form returns a logical true value, or returns that value and doesn't evaluate any of the other expressions, otherwise it returns the value of the last expression. (or) returns nil.


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


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


(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 rest/butlast.


(pos? [x])

Returns true if num is greater than zero, else false


(pr [])

(pr [x])

(pr [x & more])

Prints the object(s) to the output stream that is the current value of *out*. Prints the object(s), separated by spaces if there is more than one. By default, pr and prn print in a way that objects can be read by the reader


(pr-str [& xs])

pr to a string, returning it


(print [& more])

Prints the object(s) to the output stream that is the current value of *out*. print and println produce output for human consumption.


(print-str [& xs])

print to a string, returning it


(println [& more])

Same as print followed by (newline)


(println-str [& xs])

println to a string, returning it


(prn [& more])

Same as pr followed by (newline)


(prn-str [& xs])

prn to a string, returning it


(proxy [class-and-interfaces args & fs])

Macro

class-and-interfaces - a vector of class names args - a (possibly empty) vector of arguments to the superclass constructor. f => (name [params*] body) or (name ([params*] body) ([params+] body) ...) Expands to code which creates a instance of a proxy class that implements the named class/interface(s) by calling the supplied fns. A single class, if provided, must be first. If not provided it defaults to Object. The interfaces names must be valid interface types. If a method fn is not provided for a class method, the superclass methd will be called. If a method fn is not provided for an interface method, an UnsupportedOperationException will be thrown should it be called. Method fns are closures and can capture the environment in which proxy is called. Each method fn takes an additional implicit first arg, which is bound to 'this. Note that while method fns can be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied.


(proxy-mappings [proxy])

Takes a proxy instance and returns the proxy's fn map.


(quot [num div])

quot[ient] of dividing numerator by denominator.


(rand [])

(rand [n])

Returns a random floating point number between 0 (inclusive) and 1 (exclusive).


(rand-int [n])

Returns a random integer between 0 (inclusive) and n (exclusive).


(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 and step to 1.


(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 [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 s])

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


(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 [s])

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


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


(read [])

(read [stream])

(read [stream eof-error? eof-value])

(read [stream eof-error? eof-value recursive?])

Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. stream defaults to the current value of *in* .


(read-line [])

Reads the next line from stream that is the current value of *in* .


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


(ref [x])

Creates and returns a Ref with an initial value of x.


(ref-set [ref val])

Must be called in a transaction. Sets the value of ref. Returns val.


(refer [ns-sym & filters])

refers to all public vars of ns, subject to filters. filters can include at most one each of: :exclude list-of-symbols :only list-of-symbols :rename map-of-fromsymbol-tosymbol For each public interned var in the namespace named by the symbol, adds a mapping from the name of the var to the var to the current namespace. Throws an exception if name is already mapped to something else in the current namespace. Filters can be used to select a subset, via inclusion or exclusion, or to provide a mapping to a symbol different from the var's name, in order to prevent clashes.


(rem [num div])

rem[ainder] of dividing numerator by denominator.


(remove-method [multifn dispatch-val])

Macro

Removes the method of multimethod associated with dispatch-value.


(remove-ns [sym])

Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace.


(repeat [x])

Returns a lazy (infinite!) seq of xs.


(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


(replicate [n x])

Returns a lazy seq of n xs.


(resolve [sym])

same as (ns-resolve *ns* symbol)


(rest [coll])

Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil.


(resultset-seq [rs])

Creates and returns a lazy sequence of structmaps corresponding to the rows in the java.sql.ResultSet rs


(reverse [coll])

Returns a seq of the items in coll in reverse order. Not lazy.


(rfirst [x])

Same as (rest (first x))


(rrest [x])

Same as (rest (rest x))


(rseq [rev])

Returns, in constant time, a sequence of the items in rev (which can be a vector or sorted-map), in reverse order.


(second [x])

Same as (first (rest x))


(select-keys [map keyseq])

Returns a map containing only those entries in map whose key is in keys


(send [a f & args])

Dispatch an action to an agent. Returns the agent immediately. Subsequently, in a thread from a thread pool, the state of the agent will be set to the value of: (apply action-fn state-of-agent args)


(send-off [a f & args])

Dispatch a potentially blocking action to an agent. Returns the agent immediately. Subsequently, in a separate thread, the state of the agent will be set to the value of: (apply action-fn state-of-agent args)


(seq [coll])

Sequence. Returns a new ISeq on the collection. If the collection is empty, returns nil. (seq nil) returns nil. seq also works on Strings, native Java arrays (of reference types) and any objects that implement Iterable.


(seq? [x])

Return true if x implements ISeq


(set [coll])

Returns a set of the distinct elements of coll.


(short [x])

Coerce to short


(slurp [f])

Reads the file named by f into a string and returns it.


(some [pred coll])

Returns the first logical true value of (pred x) for any x in coll, else nil.


(sort [coll])

(sort [comp coll])

Returns a sorted sequence of the items in coll. If no comparator is supplied, the items must implement Comparable. comparator must implement java.util.Comparator.


(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, the keys must implement Comparable. comparator must implement java.util.Comparator.


(sorted-map [& keyvals])

keyval => key val Returns a new sorted map with supplied mappings.


(sorted-map-by [comparator & keyvals])

keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator.


(sorted-set [])

(sorted-set [& keys])

Returns a new sorted set with supplied keys.


(special-symbol? [s])

Returns true if s names a special form


(split-at [n coll])

Returns a vector of [(take n coll) (drop n coll)]


(split-with [pred coll])

Returns a vector of [(take-while pred coll) (drop-while pred coll)]


(str [])

(str [x])

(str [x & ys])

With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args.


(string? [x])

Return true if x is a String


(struct [s & vals])

Returns a new structmap instance with the keys of the structure-basis. vals must be supplied for basis keys in order - where values are not supplied they will default to nil.


(struct-map [s & inits])

Returns a new structmap instance with the keys of the structure-basis. keyvals may contain all, some or none of the basis keys - where values are not supplied they will default to nil. keyvals can also contain keys not in the basis.


(subs [s start])

(subs [s start end])

Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), exclusive.


(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 structure with the original and no trimming is done.


(symbol [name])

(symbol [ns name])

Returns a Symbol with the given namespace and name.


(symbol? [x])

Return true if x is a Symbol


(sync [flags-ignored-for-now & body])

Macro

transaction-flags => TBD, pass nil for now Runs the exprs (in an implicit do) in a transaction that encompasses exprs and any nested calls. Starts a transaction if none is already running on this thread. Any uncaught exception will abort the transaction and flow out of sync. The exprs may be run more than once, but any effects on Refs will be atomic.


(take [n coll])

Returns a lazy seq of the first n items in coll, or all items if there are fewer than n.


(take-nth [n coll])

Returns a lazy seq of every nth item in coll.


(take-while [pred coll])

Returns a lazy seq of successive items from coll while (pred item) returns true.


(test [v])

test [v] finds fn at key :test in var metadata and calls it, presuming failure will throw exception


(time [expr])

Macro

Evaluates expr and prints the time it took. Returns the value of expr.


(to-array [coll])

Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to java.util.Collection.toArray().


(to-array-2d [coll])

Returns a (potentially-ragged) 2-dimensional array of Objects containing the contents of coll, which can be any Collection of any Collection.


(tree-seq [branch? children root])

returns a lazy sequence of the nodes in a tree, via a depth-first walk. branch? must be a fn of one arg that returns true if passed a node that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the tree, must be a branch.


(true? [x])

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


(update-proxy [proxy mappings])

Takes a proxy instance and a map of symbols (whose names must correspond to methods of the proxy superclass/superinterfaces) to fns (which must take arguments matching the corresponding method, plus an additional (explicit) first arg corresponding to this, and updates (via assoc) the proxy's fn map. nil can be passed instead of a fn, in which case the corresponding method will revert to the default behavior. Note that this function can be used to update the behavior of an existing instance without changing its identity.


(val [e])

Returns the value in the map entry.


(vals [map])

Returns a sequence of the map's values.


(var-get [x])

Gets the value in the var object


(var-set [x val])

Sets the value in the var object to val. The var must be thread-locally bound.


(var? [v])

Returns true if v is of type clojure.lang.Var


(vector [])

(vector [& args])

Creates a new vector containing the args.


(vector? [x])

Return true if x implements IPersistentVector


(when [test & body])

Macro

Evaluates test. If logical true, evaluates body in an implicit do.


(when-first [x xs & body])

Macro

Same as (when (seq xs) (let [x (first xs)] body))


(when-let [name test & body])

Macro

Same as (let [name test] (when name body))


(when-not [test & body])

Macro

Evaluates test. If logical false, evaluates body in an implicit do.


(with-local-vars [name-vals-vec & body])

Macro

varbinding=> symbol init-expr Executes the exprs in a context in which the symbols are bound to vars with per-thread bindings to the init-exprs. The symbols refer to the var objects themselves, and must be accessed with var-get and var-set


(with-meta [obj m])

Returns an object of the same type and value as obj, with map m as its metadata.


(with-open [name init & body])

Macro

Evaluates body in a try expression with name bound to the value of init, and a finally clause that calls (. name (close)).


(with-out-str [& body])

Macro

Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls.


(xml-seq [root])

A tree seq on the xml elements as per xml/parse


(zero? [x])

Returns true if num is zero, else false


(zipmap [keys vals])

Returns a map with the keys mapped to the corresponding vals.

inspector


(inspect-table [data])

creates a graphical (Swing) inspector on the supplied regular data, which must be a sequential data structure of data structures of equal length


(inspect-tree [data])

creates a graphical (Swing) inspector on the supplied hierarchical data

set


(difference [xset yset])

Returns a set that is xset without the elements of yset.


(index [xrel ks])

Returns a map of the distinct values of ks in the xrel mapped to a set of the maps in xrel with the corresponding values of ks.


(intersection [xset yset])

Returns a set of the elements present in both xset and yset.


(join [xrel yrel])

(join [xrel yrel km])

When passed 2 rels, returns the rel corresponding to the natural join. When passed an additional keymap, joins on the corresponding keys.


(map-invert [m])

Returns the map with the vals mapped to the keys.


(project [xrel ks])

Returns a rel of the elements of xrel with only the keys in ks


(rename [xrel kmap])

Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap


(rename-keys [map kmap])

Returns the map with the keys in kmap renamed to the vals in kmap


(select [pred xset])

Returns a set of the elements for which pred is true


(union [xset yset])

Returns a set that is the union of the two sets.

xml


(parse [s])

(parse [s startparse])

Parses and loads the source s, which can be a File, InputStream or String naming a URI. Returns a tree of the xml/element struct-map, which has the keys :tag, :attrs, and :content. and accessor fns tag, attrs, and content. Other parsers can be supplied by passing startparse, a fn taking a source and a ContentHandler and returning a parser

zip


(append-child [loc item])

Inserts the item as the rightmost child of the node at this loc, without moving


(branch? [loc])

Returns true if the node at loc is a branch


(children [loc])

Returns a seq of the children of node at loc, which must be a branch


(down [loc])

Returns the loc of the leftmost child of the node at this loc, or nil if no children


(edit [loc f & args])

Replaces the node at this loc with the value of (f node args)


(end? [loc])

Returns true if loc represents the end of a depth-first walk


(insert-child [loc item])

Inserts the item as the leftmost child of the node at this loc, without moving


(insert-left [loc item])

Inserts the item as the left sibling of the node at this loc, without moving


(insert-right [loc item])

Inserts the item as the right sibling of the node at this loc, without moving


(left [loc])

Returns the loc of the left sibling of the node at this loc, or nil


(lefts [loc])

Returns a seq of the left siblings of this loc


(make-node [loc node children])

Returns a new branch node, given an existing node and new children. The loc is only used to supply the constructor.


(next [loc])

Moves to the next loc in the hierarchy, depth-first. When reaching the end, returns a distinguished loc detectable via end?. If already at the end, stays there.


(node [loc])

Returns the node at loc


(path [loc])

Returns a seq of nodes leading to this loc


(remove [loc])

Removes the node at loc, returning the loc that would have preceded it in a depth-first walk.


(replace [loc node])

Replaces the node at this loc, without moving


(right [loc])

Returns the loc of the right sibling of the node at this loc, or nil


(rights [loc])

Returns a seq of the right siblings of this loc


(root [loc])

zips all the way up and returns the root node, reflecting any changes.


(seq-zip [root])

Returns a zipper for nested sequences, given a root sequence


(up [loc])

Returns the loc of the parent of the node at this loc, or nil if at the top


(vector-zip [root])

Returns a zipper for nested vectors, given a root vector


(xml-zip [root])

Returns a zipper for xml elements (as from xml/parse), given a root element


(zipper [branch? children make-node root])

Creates a new zipper structure. branch? is a fn that, given a node, returns true if can have children, even if it currently doesn't. children is a fn that, given a branch node, returns a seq of its children. make-node is a fn that, given an existing node and a seq of children, returns a new branch node with the supplied children. root is the root node.

Copyright © Rich Hickey