por robert ross hace 12 años
366
Ver más
(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)
(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
zipmap
zipmap
function
Usage:
(zipmap keys vals)
Returns a map with the keys mapped to the corresponding vals.
with-bindings
with-bindings
macro
Usage:
(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.
while
while
macro
Usage:
(while test & body)
Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil
when-let
when-let
macro
Usage:
(when-let bindings & body)
bindings => binding-form test
When test is true, evaluates body with binding-form bound to the value of test.
when-first
when-first
macro
Usage:
(when-first bindings & body)
bindings => x xs
Same as (when (seq xs) (let [x (first xs)] body))
when
when
macro
Usage:
(when test & body)
Evaluates test. If logical true, evaluates body in an implicit do.
vector-of
vector-of
function
Usage:
(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.
vector
vector
function
Usage:
(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.
vec
vec
function
Usage:
(vec coll)
Creates a new vector containing the contents of coll.
vals
vals
function
Usage:
(vals map)
Returns a sequence of the map's values.
val
val
function
Usage:
(val e)
Returns the value in the map entry
use
use
function
Usage:
(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
update-in
take-while
take-while
function
Usage:
(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.
take-nth
take-nth
function
Usage:
(take-nth n coll)
Returns a lazy seq of every nth item in coll.
take-last
take-last
function
Usage:
(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
take
function
Usage:
(take n coll)
Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n.
subvec
subvec
function
Usage:
(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.
split-with
split-with
function
Usage:
(split-with pred coll)
Returns a vector of [(take-while pred coll) (drop-while pred coll)]
split-at
split-at
function
Usage:
(split-at n coll)
Returns a vector of [(take n coll) (drop n coll)]
sorted-map
sorted-map
function
Usage:
(sorted-map & keyvals)
keyval => key val
Returns a new sorted map with supplied mappings
sort-by
sort-by
function
Usage:
(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.
sort
sort
function
Usage:
(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.
some-fn
some-fn
function
Usage:
(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.
some
some
function
Usage:
(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)
shuffle
shuffle
function
Usage:
(shuffle coll)
Return a random permutation of coll
select-keys
select-keys
function
Usage:
(select-keys map keyseq)
Returns a map containing only those entries in map whose key is in keys
second
second
function
Usage:
(second x)
Same as (first (next x))
satisfies?
satisfies?
function
Usage:
(satisfies? protocol x)
Returns true if x satisfies the protocol
reverse
reverse
function
Usage:
(reverse coll)
Returnss a seq of the items in coll in reverse order. Not lazy.
rest
rest
function
Usage:
(rest coll)
Returns a possibly empty seq of the items after the first. Calls seq on its argument.
reset!
reset!
function
Usage:
(reset! atom newval)
Sets the value of atom to newval without regard for the current value. Returns newval.
require
require
function
Usage:
(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.
replace
replace
function
Usage:
(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.
repeatedly
repeatedly
function
Usage:
(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.
repeat
repeat
function
Usage:
(repeat x)
(repeat n x)
Returns a lazy (infinite!, or length n if supplied) sequence of xs.
remove
remove
function
Usage:
(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.
reify
reify
macro
Usage:
(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)*
ref-set
ref-set
function
Usage:
(ref-set ref val)
Must be called in a transaction. Sets the value of ref. Returns val.
ref
ref
function
Usage:
(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)
reductions
reductions
function
Usage:
(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.
reduce-kv
reduce-kv
function
Usage:
(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.
reduce
reduce
function
Usage:
(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.
re-seq
re-seq
function
Usage:
(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.
re-pattern
re-pattern
function
Usage:
(re-pattern s)
Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher.
re-matches
re-matches
function
Usage:
(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-matcher
re-matcher
function
Usage:
(re-matcher re s)
Returns an instance of java.util.regex.Matcher, for use, e.g. in re-find.
re-groups
re-groups
function
Usage:
(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-find
re-find
function
Usage:
(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.
range
range
function
Usage:
(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.
rand-nth
rand-nth
function
Usage:
(rand-nth coll)
Return a random element of the (sequential) collection. Will have the same performance characteristics as nth for the given collection.
rand-int
rand-int
function
Usage:
(rand-int n)
Returns a random integer between 0 (inclusive) and n (exclusive).
rand
rand
function
Usage:
(rand)
(rand n)
Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive).
promise
promise
function
Usage:
(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?
pop
pop
function
Usage:
(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.
pmap
pmap
function
Usage:
(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.
persistent!
persistent!
function
Usage:
(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.
peek
peek
function
Usage:
(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.
pcalls
pcalls
function
Usage:
(pcalls & fns)
Executes the no-arg fns in parallel, returning a lazy sequence of their values.
partition-by
partition-by
function
Usage:
(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.
partition-all
partition-all
function
Usage:
(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
partition
function
Usage:
(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.
partial
partial
function
Usage:
(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.
nth
nth
function
Usage:
(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.
next
next
function
Usage:
(next coll)
Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil.
nfirst
nfirst
function
Usage:
(nfirst x)
Same as (next (first x))
nnext
nnext
function
Usage:
(nnext x)
Same as (next (next x))
not-any?
not-any?
function
Usage:
(not-any? pred coll)
Returns false if (pred x) if logical true for any x in coll, else true.
not-every?
not-every?
function
Usage:
(not-every? pred coll)
Returns false if (pred x) is logical true for every x in coll, else true.
merge-with
merge-with
function
Usage:
(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).
merge
merge
function
Usage:
(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.
memoize
memoize
function
Usage:
(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.
mapv
mapv
function
Usage:
(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.
mapcat
mapcat
function
Usage:
(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.
map-indexed
map-indexed
function
Usage:
(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.
map
map
function
Usage:
(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.
loop
loop
macro
Usage:
(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.
list*
list*
fuction
Usage:
(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.
list
list
function
Usage:
(list & items)
Creates a new list containing the items
line-seq
line-seq
function
Usage:
(line-seq rdr)
Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader
letfn
letfn
macro
Usage:
(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.
let
let
macro
Usage:
(let bindings & body)
bindings => binding-form init-expr
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.
lazy-seq
lazy-seq
macro
Usage: (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?
lazy-cat
lazy-cat
macro
Usage:
(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))
last
last
function
Usage:
(last coll)
Return the last item in coll, in linear time
keys
keys
function
Usage:
(keys map)
Reurns a sequence of the map's keys.
key
key
function
Usage:
(key e)
Returns the key of the map entry.
keep-indexed
keep-indexed
function
Usage:
(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.
keep
keep
function
Usage: (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.
juxt
juxt
funtionn
Usage:
(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)]
iterate-seq
iterator-seq
function
Usage:
(iterator-seq iter)
Returns a seq on a java.util.Iterator. note that most collections provided iterators implement Iterable and thus support seq directly.
iterate
iterate
function
Usage:
(iterate f x)
Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects
into
into
function
Usage:
(into to from)
Returns a new coll consisting of to-coll with all of the items of from-coll conjoined.
interpose
interpose
function
Usage:
(interpose sep col)
Returns a lazy seq of the elements of coll seperated by sep
import
import
macro
Usage:
(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.
if-not
if-not
macro
Usage:
(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.
if-let
if-let
macro
Usage:
(if-let bindings then)
(if-let bindings then else & oldform)
bindings => binding-form test
If test is true, evaluates then with binding-form bound to the value of the test, if not yields else
hash-map
hash-map
function
Usage:
(hash-map)
(hash-map & keyvals)
keyval => key val
Returns a new hash map with supplied mappings.
group-by
group-by
function
Usage:
(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.
get-method
get-method
function
Usage:
(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
get-in
get-in
function
Usage:
(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
get
function
Usage:
(get map key)
(get map keye not-found)
Returns the value mapped to key, not-found or nil if key not present.
future-cancelled?
future-cancelled?
function
Usage:
(future-cancelled? f)
Returns true if future f is cancelled
future-done?
future-done?
function
Usage:
(future-done? f)
Returns true if future f is done
future-cancel
future-cancel
function
Usage:
(future-cancel f)
Cancels the future, if possible.
future-call
future-call
function
Usage: (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
future
macro
Usage:
(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?.
frequencies
frequencies
function
Usage:
(frequencies coll)
Returns a map from distinct items in coll to the number of times they appear.
format
format
function
Usage:
(format fmt & args)
Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax
force
force
function
Usage:
(force x)
If x is a Delay, returns the (possibly cached) value of its expression, else returns x
for
for
macro
Usage:
(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]))
fnil
fnil
function
Usage:
(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.
flatten
flatten
function
Usage:
(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.
first
first
function
Usage:
(first coll)
Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil.
find
find
function
Usage:
(find map key)
Returns the map entry for key, or nil if key not present
filterv
filterv
function
Usage:
(filterv pred coll)
Returns a vector of the items in coll for which (pred item) returns true. pred must be free fo side-effects.
filter
filter
function
Usage:
(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.
ffirst
ffirst
function
Usage:
(ffirst x)
Same as (first (first x))
every?
every?
function
Usage:
(every? pred coll)
Returns true if (pred x) is logical true for every x in coll, else false.
every-pred
every-pred
function
Usage:
(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.
ensure
ensure
function
Usage:
(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)
empty?
empty?
function
Usage:
(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))
empty
empty
function
Usage:
(empty coll)
Returns an empty collection of the same category as coll, or nil
drop-while
drop-while
function
Usage: (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.
drop-last
drop-last
function
Usage:
(drop-last s)
(drop-last n s)
Return a lazy sequence of all but the last n (default 1) items in coll
drop
drop
function
Usage:
(drop n coll)
Returns a lazy sequence of all but the first n items in coll.
doto
doto
macro
Usage:
(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))
dotimes
dotimes
macro
Usage: (dotimes bindings & body)
bindings => name n
Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1.
doseq
doseq
macro
Usage:
(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.
dorun
dorun
function
Usage:
(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.
doall
doall
function
Usage:
(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.
distinct?
distinct?
function
Usage:
(distinct? x)
(distinct? x y)
(distinct? x y & more)
Returns true if no two of the argumenst are =
distinct
distinct
function
Usage:
(distinct coll)
Returns a lazy sequence of the elements of coll with duplicates removed.
dissoc
dissoc
function
Usage:
(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).
disj
disj
function
Usage:
(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).
derive
derive
function
Usage:
(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.
deref
deref
function
Usage:
(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?.
delay?
delay?
function
Usage: (delay? x)
returns true if x is a Delay created with delay
delay
delay
macro
Usage:
(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?
defmulti
defmulti
macro
Usage:
(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
(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)])))
defmacro
defmacro
macro
Usage:
(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.
cycle
cycle
function
Usage:
(cycle coll)
Returns a lazy (infinite!) sequence of repititions of the items in coll.
count
count
function
Usage:
(count coll)
Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps.
contains?
contains?
function
Usage:
(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'.
constantly
constantly
function
Usage:
(constantly x)
Returns a function that takes any number of arguments and returns x.
cons
cons
function
Usage:
(cons x seq)
returns a new seq where x is the first element and seq is the rest.
conj
conj
function
Usage:
(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.
condp
condp
macro
Usage:
(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-expr
test-expr :>> result-fn
Note :>> 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.
cond
cond
macro
Usage:
(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.
concat
concat
function
Usage:
(concat)
(concat x)
(concat x y)
(concat x y & zs)
Returns a lazy seq representing the concatenation of the elements in the supplied colls
compile
compile
function
Usage
(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.
case
case
macro
Usage:
(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-expr
The 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))
comp
comp
function
Usage:
(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.
butlast
butlast
function
Usage:
(butlast coll)
Return a seq of all but the last item in coll, in linear time
bound-fn
bound-fn
macro
Usage:
(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.
binding
binding
macro
Usage:
(binding bindings & body)
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. 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?)
bases
bases
function
Usage:
(bases c)
Returns the immediate superclass and direct interfaces of c, if any
atom
atom
function
Usage:
(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-fn
If 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.
associative?
associative?
function
Usage:
(associative? coll)
Returns true if coll implements Associative
assoc-in
assoc-in
function
Usage:
(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.
assoc
assoc
function
Usage:
(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).
array-map
array-map
function
Usage:
(array-map)
(array-map & keyvals)
Constructs an array-map
areduce
areduce
macro
Usage:
(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.
apply
apply
function
Usage:
(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.
amap
amap
macro
Usage:
(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.
alter
alter
function
Usage:
(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.
alength
alength
function
Usage: (alength array)
Returns the length of the Java array. Works on arrays of all types.
aget
aget
function
Usage:
(aget array idx)
(aget array idx & idx)
Returns the value at the index/indices. Works on Java arrays of all types.
agent
agent
function
Usage:
(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-keyword
If 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.
add-watch
add-watch
function
Usage:
(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.
accessor
accessor
function
Usage:
(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.
==
function
Usage:
(== x)
(== x y)
(== x y & more)
Returns non-nil if nums all have the equivalent value (type-independent), otherwise false
..
macro
Usage:
(.. 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.
->>
macro
Usage;
(->> 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.
->
macro
Usage:
(-> 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 a
list already. If there are more forms, inserts the first form as the
second item in second form, etc.