clove

Core functions

The 329 names that (doc ...) knows about, grouped as in docs.clj. The REPL prints the same text: (doc map). Names that clove shares with Clojure behave as in Clojure; the Clojure cheatsheet covers them in more depth.

Sequences

map

(map f)
(map f coll)
(map f c1 c2)
(map f c1 c2 & colls)

Returns a lazy sequence of applying f to each item of coll (or to the items of multiple colls in parallel, stopping at the shortest). (map f) returns a transducer.

filter

(filter pred)
(filter pred coll)

Returns a lazy sequence of the items in coll for which (pred item) is logical true. (filter pred) returns a transducer.

remove

(remove pred)
(remove pred coll)

Returns a lazy sequence of the items for which (pred item) is logical false.

reduce

(reduce f coll)
(reduce f init coll)

(reduce f coll) or (reduce f init coll): applies f to an accumulator and each item, left to right. With no init, first two items seed the call; empty coll => (f).

reductions

(reductions f coll)
(reductions f init coll)

Returns a lazy seq of the intermediate values of a reduction, starting with init (or the first item).

reduce-kv

(reduce-kv f init coll)

Reduces an associative collection: (f acc key val) for every entry. Vectors use their indices as keys.

mapcat

(mapcat f)
(mapcat f & colls)

Applies f to every item and concatenates the (collection) results, lazily.

mapv

(mapv f coll)
(mapv f c1 c2)
(mapv f c1 c2 & colls)

Like map but eager, returning a vector.

filterv

(filterv pred coll)

Like filter but eager, returning a vector.

keep

(keep f)
(keep f coll)

Lazy sequence of the non-nil results of (f item).

keep-indexed

(keep-indexed f)
(keep-indexed f coll)

Lazy sequence of the non-nil results of (f index item).

map-indexed

(map-indexed f)
(map-indexed f coll)

Lazy sequence of (f index item) for each item.

take

(take n)
(take n coll)

Lazy sequence of the first n items. (take n) is a transducer.

drop

(drop n)
(drop n coll)

Lazy sequence of all but the first n items.

take-while

(take-while pred)
(take-while pred coll)

Lazy items from the front while (pred item) is true.

drop-while

(drop-while pred)
(drop-while pred coll)

Lazy items after the leading run where (pred item) is true.

take-nth

(take-nth n)
(take-nth n coll)

Every nth item of coll, lazily.

take-last

(take-last n coll)

The last n items of coll (eager).

drop-last

(drop-last coll)
(drop-last n coll)

All but the last n items, lazily.

first

(first coll)

The first item of coll, or nil when empty.

second

(second coll)

Same as (first (next coll)).

rest

(rest coll)

The items after the first; () when none. Never nil.

last

(last coll)

The final item of coll (walks the whole seq).

butlast

(butlast coll)

Everything but the final item (eager).

nth

(nth coll index)
(nth coll index not-found)

The item at index n. Throws when out of bounds unless a not-found is given.

cons

(cons x seq)

A seq whose first is x and whose rest is coll.

conj

(conj coll)
(conj coll x)
(conj coll x & xs)

Adds item(s) to a collection at its natural insertion point: vectors append, lists prepend, sets/maps add.

concat

(concat)
(concat x)
(concat x y)
(concat x y & zs)

Lazy concatenation of any number of collections.

into

(into to from)
(into to xform from)

Adds every item of `from` onto `to` (conj semantics); (into to xform from) applies a transducer.

seq

(seq coll)

A seq view of the collection, or nil when it is empty. The idiomatic emptiness test.

empty?

(empty? coll)

True when coll has no items — same as (not (seq coll)).

count

(count coll)

The number of items in the collection (O(1) for counted colls).

range

(range)
(range end)
(range start end)
(range start end step)

(range), (range end), (range start end step): lazy seq of numbers. No args = infinite.

repeat

(repeat x)
(repeat n x)

(repeat x) infinite xs; (repeat n x) n of them. Lazy.

repeatedly

(repeatedly f)
(repeatedly n f)

Lazy sequence of calls to a zero-arg (side-effecting) fn.

iterate

(iterate f x)

Lazy infinite seq of x, (f x), (f (f x)), ...

cycle

(cycle coll)

Lazy infinite repetition of the items of coll.

interleave

(interleave)
(interleave c1)
(interleave c1 c2)
(interleave c1 c2 & colls)

First items of each coll, then second items, etc., stopping at the shortest.

interpose

(interpose sep)
(interpose sep coll)

The items of coll separated by sep, lazily.

partition

(partition n coll)
(partition n step coll)
(partition n step pad coll)

Lazy blocks of n items (optionally stepped/padded); incomplete tail block is dropped unless padded.

partition-all

(partition-all n)
(partition-all n coll)
(partition-all n step coll)

Like partition but keeps the incomplete final block.

partition-by

(partition-by f)
(partition-by f coll)

Splits coll each time (f item) changes value, lazily.

split-at

(split-at n coll)

[(take n coll) (drop n coll)]

split-with

(split-with pred coll)

[(take-while pred coll) (drop-while pred coll)]

distinct

(distinct)
(distinct coll)

Lazy sequence with duplicates removed.

dedupe

(dedupe)
(dedupe coll)

Lazy sequence with consecutive duplicates collapsed.

flatten

(flatten coll)

All nested sequential items as one flat lazy sequence.

reverse

(reverse coll)

The items in reverse order (eager).

sort

(sort coll)
(sort comp coll)

Sorted seq of coll; (sort comp coll) with a comparator.

sort-by

(sort-by keyfn coll)
(sort-by keyfn comp coll)

Sorts by (keyfn item), optionally with a comparator.

shuffle

(shuffle coll)

A random permutation of coll (note: clove's is currently identity).

frequencies

(frequencies coll)

Map from distinct item to number of occurrences.

group-by

(group-by f coll)

Map from (f item) to vector of items with that key.

doall

(doall coll)
(doall n coll)

Forces a lazy sequence completely; returns it. Use for side effects held in a lazy seq.

dorun

(dorun coll)
(dorun n coll)

Forces a lazy sequence for side effects; returns nil.

lazy-seq

(lazy-seq & body)

Wraps body so it is evaluated only when the seq is consumed, once.

realized?

Whether a delay/lazy value has been forced (clove: coarse).

some

(some pred coll)

The first logical-true value of (pred item), else nil.

every?

(every? pred coll)

True if (pred item) is true for every item.

not-every?

(not-every? pred coll)

Complement of every?.

not-any?

(not-any? pred coll)

True when no item satisfies pred.

zipmap

(zipmap keys vals)

A map with keys mapped to vals, stopping at the shorter.

line-seq

Lazy seq of lines from a reader.

tree-seq

(tree-seq branch? children root)

Lazy depth-first walk: branch? decides descent, children expands.

Collections

get

(get map key)
(get map key not-found)

The value at key (or index), or not-found/nil. Works on maps, vectors, sets, strings.

get-in

(get-in m ks)
(get-in m ks not-found)

The value at a nested key path, e.g. (get-in m [:a :b]).

assoc

(assoc map key val)
(assoc map key val & kvs)

Map with key(s) mapped to val(s); on vectors, sets the index (append at count).

assoc-in

(assoc-in m ks v)

Sets a value at a nested key path, creating maps along the way.

update

(update m k f)
(update m k f x)
(update m k f x y)
(update m k f x y & more)

Map with the value at k replaced by (f old & args).

update-in

(update-in m ks f & args)

Like update at a nested key path.

dissoc

(dissoc map)
(dissoc map key)
(dissoc map key & ks)

Map without the given key(s).

disj

(disj set)
(disj set k)
(disj set k & ks)

Set without the given element(s).

merge

(merge & maps)

Later maps' entries win: (merge {:a 1} {:a 2 :b 3}) => {:a 2 :b 3}.

merge-with

(merge-with f & maps)

Like merge, resolving key conflicts with (f left right).

select-keys

(select-keys map keyseq)

Map with only the entries whose keys are in keyseq.

keys

(keys map)

Sequence of the map's keys.

vals

(vals map)

Sequence of the map's values.

contains?

(contains? coll key)

Whether the key (or index) is present — NOT a value search; use `some` for that.

find

(find map key)

The map entry [k v] for key, or nil.

peek

(peek coll)

Vectors: last item. Lists/queues: first. Maps (clove): the min-priority entry.

pop

(pop coll)

The collection without its peek item.

subvec

(subvec v start)
(subvec v start end)

A vector view of v from start (to end), O(1).

vec

(vec coll)

An eager vector of the items of coll.

vector

(vector & items)

A vector of the arguments.

set

(set coll)

A set of the items of coll.

hash-map

(hash-map & keyvals)

A map from interleaved key/value arguments.

hash-set

(hash-set & keys)

A set of the arguments.

sorted-map

(sorted-map & keyvals)

A map sorted by its keys (compare, or sorted-map-by comparator).

sorted-set

(sorted-set & keys)

A set sorted by compare (or sorted-set-by comparator).

subseq

Entries of a sorted collection in a key range, e.g. (subseq sm >= 5).

rsubseq

Like subseq, descending.

transient

(transient coll)

A mutable-in-place edition of a vector/map/set for batch building; finish with persistent!.

persistent!

(persistent! coll)

Seals a transient back into an immutable collection.

conj!

(conj! coll x)

conj onto a transient.

assoc!

(assoc! coll key val)

assoc onto a transient (or set an int-array slot in clove).

int-array

(int-array size)
(int-array size init-or-seq)

(int-array n), (int-array n init), (int-array coll): a flat mutable int64 array (clove native). Use aget/aset/alength.

aget

(aget array idx)

Reads array slot i, O(1).

aset

(aset array idx val)

Writes array slot i, returning the value.

alength

(alength array)

The array's length.

empty

(empty coll)

An empty collection of the same category as coll.

Functions & control

apply

(apply f args)
(apply f x args)
(apply f x y args)
(apply f x y z & args)

Calls f with the items of the final argument spliced in as arguments.

partial

(partial f)
(partial f arg1)
(partial f arg1 arg2)
(partial f arg1 arg2 arg3 & more)

A fn with some leading arguments preapplied.

comp

(comp)
(comp f)
(comp f g)
(comp f g & fs)

Right-to-left function composition: ((comp f g) x) is (f (g x)).

juxt

(juxt f)
(juxt f g)
(juxt f g h)
(juxt f g h & fs)

((juxt f g) x) => [(f x) (g x)].

identity

(identity x)

Returns its argument.

constantly

(constantly x)

A fn that ignores its arguments and always returns x.

fnil

(fnil f x)
(fnil f x y)
(fnil f x y z)

A fn that substitutes defaults for leading nil arguments before calling f.

complement

(complement f)

A fn returning the logical negation of f's result.

every-pred

A pred that is true when ALL given preds are true.

some-fn

A fn returning the first logical-true result among the given fns.

memoize

Caches f's results by argument list.

trampoline

Calls f; while the result is a fn, calls it — flat mutual recursion.

if-let

Binds then branches: (if-let [x expr] then else) — then runs with x bound when expr is truthy.

when-let

(when-let [x expr] body...) — body runs with x bound when expr is truthy.

if-some

Like if-let but tests (some? expr), so false is a hit.

when-some

Like when-let but tests (some? expr).

cond

Pairs of test/expr: value of the expr after the first truthy test.

condp

(condp pred expr & clauses): matches expr against clause keys with pred.

case

Constant-time dispatch on identical(ish) constants; throws without a default.

cond->

Threads x through the exprs whose paired tests are truthy.

cond->>

Like cond-> threading last.

as->

Threads through forms binding each result to the given name.

some->

Threads while values are non-nil; stops at the first nil.

some->>

Like some-> threading last.

doto

Evaluates x, threads it as first arg through the forms (for side effects), returns x.

dotimes

(dotimes [i n] body): runs body n times with i bound 0..n-1.

doseq

Iterates for side effects with for-style bindings (:let/:when/:while); returns nil.

for

Lazy list comprehension with :let/:when/:while modifiers.

loop

Establishes bindings that recur re-enters with new values.

recur

Rebinds the enclosing loop/fn bindings and jumps back — constant-stack iteration.

while

Runs body repeatedly while test is truthy.

run!

(reduce (fn [_ x] (f x)) nil coll) — eager side effects, returns nil.

Numbers

inc

(inc x)

One greater.

dec

(dec x)

One less.

quot

(quot num div)

Truncating integer division.

rem

(rem num div)

Remainder with the dividend's sign.

mod

(mod num div)

Modulus with the divisor's sign (always ≥0 for positive divisors).

max

(max x)
(max x y)
(max x y & more)

The greatest argument.

min

(min x)
(min x y)
(min x y & more)

The least argument.

abs

(abs a)

Absolute value.

gcd

Greatest common divisor (clove extension).

even?

(even? n)

Whether n is even.

odd?

(odd? n)

Whether n is odd.

zero?

(zero? num)

Whether x is zero.

pos?

(pos? num)

Whether x is positive.

neg?

(neg? num)

Whether x is negative.

parse-long

The string as a long, or nil if it isn't one.

parse-double

The string as a double, or nil.

rand

(rand)
(rand n)

Random double in [0,n) (default n=1).

rand-int

(rand-int n)

Random integer in [0,n).

rand-nth

(rand-nth coll)

A random item of coll.

compare

(compare x y)

-1/0/1 comparator over comparable values (numbers, strings, keywords, vectors...).

Strings

str

(str)
(str x)
(str x & ys)

Concatenates the string forms of the arguments; nil is "".

pr-str

(pr-str & xs)

The readable (edn) printed form as a string.

prn

(prn & xs)

Prints readably followed by a newline.

println

(println & xs)

Prints human-readably with spaces and a newline.

print

(print & xs)

Prints human-readably without a newline.

format

(format fmt & args)

printf-style formatting: %s %d %f %x etc.

subs

(subs s start)
(subs s start end)

Substring from start (to end).

str/join

(str/join coll)
(str/join separator coll)

Concatenates the collection's items, optionally separated: (str/join ", " xs).

str/split

(str/split s re)
(str/split s re limit)

Splits on a regex: (str/split s #"," limit?).

str/split-lines

(str/split-lines s)

Splits on \n (and \r\n).

str/replace

(str/replace s match replacement)

Replaces all matches of a string or #"regex" (with $1.. group refs or a fn).

str/replace-first

(str/replace-first s match replacement)

Like str/replace, first match only.

str/trim

(str/trim s)

Without leading/trailing whitespace.

str/triml

(str/triml s)

Without leading whitespace.

str/trimr

(str/trimr s)

Without trailing whitespace.

str/upper-case

(str/upper-case s)

ALL CAPS.

str/lower-case

(str/lower-case s)

all lower.

str/capitalize

(str/capitalize s)

First char upper, rest lower.

str/starts-with?

(str/starts-with? s substr)

Whether s begins with substr.

str/ends-with?

(str/ends-with? s substr)

Whether s ends with substr.

str/includes?

(str/includes? s substr)

Whether s contains substr.

str/index-of

(str/index-of s value)
(str/index-of s value from-index)

First index of a substring/char, or nil.

str/last-index-of

(str/last-index-of s value)
(str/last-index-of s value from-index)

Last index of a substring/char, or nil.

str/blank?

(str/blank? s)

True for nil, empty, or all-whitespace strings.

str/reverse

(str/reverse s)

The string reversed.

Regex

re-find

(re-find re s)

First match of the pattern in s: the string, or [match groups...] when the pattern has groups.

re-matches

(re-matches re s)

Like re-find but the pattern must match the ENTIRE string.

re-seq

(re-seq re s)

Lazy sequence of successive matches.

re-pattern

(re-pattern s)

Compiles a string into a regex pattern.

re-replace

clove: replace all matches, with $1..$9 group refs in the replacement.

State

atom

(atom x)

A mutable reference; read with @, update with swap!/reset!.

swap!

(swap! atom f)
(swap! atom f x)
(swap! atom f x y)
(swap! atom f x y & args)

Sets an atom to (f current args...); returns the new value.

reset!

(reset! atom newval)

Sets an atom's value directly; returns it.

swap-vals!

Like swap! but returns [old new].

reset-vals!

Like reset! but returns [old new].

compare-and-set!

Sets the atom to new only if it currently holds old; returns success.

deref

(deref ref)

The current value of an atom/delay/promise/var — reader sugar @x.

delay

Defers body until the first deref, then caches.

force

Derefs a delay, passes other values through.

Predicates & misc

nil?

(nil? x)

Whether x is nil.

some?

(some? x)

Whether x is NOT nil (false is some?).

true?

(true? x)

Whether x is exactly true.

false?

(false? x)

Whether x is exactly false.

not

(not x)

Logical negation.

boolean

(boolean x)

Coerces to true/false by truthiness.

string?

(string? x)

Whether x is a string.

keyword?

(keyword? x)

Whether x is a keyword.

symbol?

(symbol? x)

Whether x is a symbol.

number?

(number? x)

Whether x is a number.

int?

(int? x)

Whether x is a fixed-precision integer.

integer?

Whether x is any integer.

double?

Whether x is a double.

fn?

(fn? x)

Whether x is a function.

coll?

(coll? x)

Whether x is a collection.

seq?

(seq? x)

Whether x is a seq (list-like).

sequential?

(sequential? coll)

Whether x is sequential (lists, vectors, seqs).

associative?

(associative? coll)

Whether x supports key lookup (maps, vectors).

vector?

(vector? x)

Whether x is a vector.

map?

(map? x)

Whether x is a map.

set?

(set? x)

Whether x is a set.

list?

(list? x)

Whether x is a list.

sorted?

Whether x is a sorted collection.

keyword

(keyword name)
(keyword ns name)

Makes a keyword from a name (and optional namespace): (keyword "a" "b") => :a/b.

symbol

(symbol name)
(symbol ns name)

Makes a symbol from a name (and optional namespace).

name

(name x)

The name part of a keyword/symbol/string.

namespace

(namespace x)

The namespace part of a qualified keyword/symbol, or nil.

gensym

(gensym)
(gensym prefix-string)

A unique symbol, optionally with a prefix.

type

(type x)

The value's type (clove: a keyword like :vector, :string).

instance?

(instance? c x)

Whether x is of the given type/protocol.

identical?

Pointer equality — same object.

hash

The value's hash code (consistent with =).

meta

(meta obj)

The metadata map of obj, or nil.

with-meta

(with-meta obj m)

obj with the given metadata map attached.

vary-meta

(vary-meta obj f & args)

obj with (apply f (meta obj) args) as metadata.

slurp

(slurp f)

The entire contents of a file/stream as a string.

spit

(spit f content)

Writes content to a file (stringified).

read-string

(read-string s)

Reads one edn/Clojure form from the string.

eval

(eval form)

Evaluates a form (data) and returns the result.

macroexpand-1

One step of macro expansion for the form.

macroexpand

Repeated macroexpand-1 until the head is no longer a macro.

time

Evaluates body, prints elapsed time, returns the value.

assert

Throws when x is falsy (with optional message).

ex-info

An exception carrying a message and a data map (and optional cause).

ex-message

The message of an exception.

ex-data

The data map of an ex-info exception, else nil.

ex-cause

The cause of an exception, or nil.

with-out-str

Evaluates body capturing everything printed, returning it as a string.

doc

Prints documentation for the named binding: (doc map).

source

Prints the (re-read) source of a fn defined from Clojure code: (source my-fn).

apropos

All defined names containing the string: (apropos "index").

find-doc

Prints docs for every binding whose name or docstring matches.

Multimethods & protocols

defmulti

Defines a multimethod dispatching on (dispatch-fn args...).

defmethod

Adds a method implementation for a dispatch value.

defprotocol

Declares a named set of methods dispatched on the first argument's type.

defrecord

Defines a named map-like type with fixed fields and protocol support.

deftype

Defines a named type with fields (clove: represented as a tagged map).

derive

Adds a parent relationship in the (global) hierarchy.

isa?

Hierarchy-aware type/tag relation (vectors compare element-wise).

Batteries

fs/exists?

Whether the path exists.

fs/directory?

Whether the path is a directory.

fs/regular-file?

Whether the path is a regular file.

fs/list-dir

Sequence of entries in a directory.

fs/create-dir

Creates the directory (and parents); true on success.

fs/delete

Deletes a file or (empty) directory; true on success.

fs/move

Renames/moves src to dst; true on success.

fs/copy

Copies src to dst.

fs/file-name

The final path segment.

fs/parent

The parent directory of the path, or nil.

fs/extension

The file extension without the dot, or nil.

fs/temp-dir

The system temp directory.

fs/cwd

The current working directory.

http/serve

Starts the HTTP server on the csp event loop; returns the listening socket (drive with (csp/run!)). Handler gets a request map, returns a string or {:status :headers :body}.

http/run-server

Starts the HTTP server and blocks, driving the csp event loop.

http/router

Builds a handler from route entries [[method path-pattern handler] ...].

http/request

Performs an HTTP request from {:method :url :headers :body}; returns a channel of the response map.

http/get

HTTP GET of a url; returns a channel of the response map.

http/post

HTTP POST of a body to a url; returns a channel of the response map.

json/parse

Parses a JSON string to Clojure data ((json/parse s) or (json/parse s {:keywords? true})).

json/write

Renders Clojure data as a JSON string.

peg/match

Matches a Janet-style PEG (pattern data, grammar map with :main, or compiled) at start of text; returns the capture vector or nil. (peg/match peg text ?start & args).

peg/compile

Compiles a PEG pattern once; the result is a fn (m text ?start & args) => captures, accepted anywhere a pattern is.

peg/find

Index of the first position at/after start where the PEG matches, or nil.

peg/find-all

Vector of every position in text where the PEG matches.

peg/replace

Replaces the first PEG match in text with subst: a string, or a fn of (matched-text & captures).

peg/replace-all

Replaces every PEG match in text with subst (string or fn of (matched-text & captures)).

process/sh

Runs a shell command, returns {:exit :out} (stderr folded into :out).

process/shell

Like process/sh but throws ex-info on nonzero exit.

process/out

The trimmed stdout of running the command.

process/escape

Shell-escapes a string for safe interpolation.

Special forms & core macros

if

(if test then else?)

Special form. Evaluates test; if truthy (anything but nil/false), evaluates and returns then, otherwise else (or nil).

do

(do exprs*)

Special form. Evaluates the exprs in order, returns the last (nil when empty).

let

(let [bindings*] exprs*)

Special form. Binds names to values in order (later bindings see earlier ones); evaluates body with them in scope. Destructuring supported.

fn

(fn name? [params*] exprs*)
(fn name? ([params*] exprs*) +)

Special form. An anonymous function; multiple arity clauses allowed, & gathers rest args. #(...) is shorthand with % %1 %2.

def

(def symbol doc-string? init?)

Special form. Interns a root binding for the symbol, optionally with a docstring and init value.

loop

(loop [bindings*] exprs*)

Special form. Like let, but marks a recur target: (recur ...) rebinds the loop bindings and jumps back without consuming stack.

recur

(recur exprs*)

Special form. Rebinds the enclosing loop/fn bindings to the given values and jumps back — clove's tail call. Must be in tail position.

quote

(quote form)

Special form. Returns the form unevaluated. 'x reads as (quote x).

var

(var symbol)

Special form. Returns the Var named by the symbol (also #'sym). Its meta carries :name/:doc/:arglists.

throw

(throw expr)

Special form. Throws a value; catch it with try/catch. Use ex-info to build data-carrying exceptions.

try

(try exprs* (catch Exception e exprs*) ? (finally exprs*) ?)

Special form. Evaluates body; on a throw, the first matching catch clause runs with the exception bound; finally always runs.

when

(when test exprs*)

Macro. Evaluates body when test is truthy, else nil. No else branch — use if for that.

when-not

(when-not test exprs*)

Macro. Evaluates body when test is falsey.

when-let

(when-let [sym test] exprs*)

Macro. Binds the value of test; evaluates body when it is truthy.

when-some

(when-some [sym test] exprs*)

Macro. Like when-let but tests for non-nil rather than truthy.

if-let

(if-let [sym test] then else?)

Macro. Binds the value of test; if truthy evaluates then with it bound, else else.

if-some

(if-some [sym test] then else?)

Macro. Like if-let but tests for non-nil (false counts as some).

if-not

(if-not test then else?)

Macro. (if (not test) then else).

and

(and)
(and x)
(and x & next)

Macro. Evaluates left to right, returns the first falsey value or the last value. () => true.

or

(or)
(or x)
(or x & next)

Macro. Evaluates left to right, returns the first truthy value or the last value. () => nil.

->

(-> x & forms)

Macro. Thread-first: inserts each result as the SECOND item of the next form. (-> x (f a) g) => (g (f x a)).

->>

(->> x & forms)

Macro. Thread-last: inserts each result as the LAST item of the next form. (->> x (f a) g) => (g (f a x)).

as->

(as-> expr name & forms)

Macro. Threads x through forms with an explicit name for the previous result.

some->

(some-> expr & forms)

Macro. Thread-first, but stops (returns nil) at the first nil result.

some->>

(some->> expr & forms)

Macro. Thread-last, short-circuiting on nil.

cond->

(cond-> expr & test-form-pairs)

Macro. Threads expr through the forms whose paired test is truthy (tests are NOT threaded).

doto

(doto x & forms)

Macro. Evaluates x, calls each form with x inserted second (for side effects), returns x.

dotimes

(dotimes [name n] exprs*)

Macro. Runs body n times with the name bound to 0..n-1; returns nil.

doseq

(doseq [seq-exprs*] exprs*)

Macro. Iterates the seq(s) for side effects; supports :let :when :while like for. Returns nil.

for

(for [seq-exprs*] body-expr)

Macro. List comprehension: lazy seq of body evaluated across the bindings; modifiers :let :when :while.

defn

(defn name doc-string? [params*] exprs*)
(defn name doc-string? ([params*] exprs*) +)

Macro. (def name (fn ...)) with docstring and multi-arity support; registers the docstring for (doc name).

defn-

(defn- name doc-string? [params*] exprs*)

Macro. Like defn but marks the var private to its namespace.

defmacro

(defmacro name doc-string? [params*] exprs*)

Macro. Defines a macro: the fn receives unevaluated forms and returns a replacement form.

defonce

(defonce name expr)

Macro. defs the value only if the symbol has no root binding yet.

declare

(declare & names)

Macro. Forward-declares names so later defs can be referenced before definition.

binding

(binding [var-val-pairs*] exprs*)

Macro. Temporarily rebinds dynamic (root) vars for the extent of the body, restoring on exit.

with-redefs

(with-redefs [var-val-pairs*] exprs*)

Macro. Temporarily rebinds the root values of vars for the extent of the body, restoring them afterwards, even on a throw. Visible to all code, unlike binding.

letfn

(letfn [(name [params*] exprs*) +] exprs*)

Macro. Binds locally-scoped, mutually recursive fns for the body.

case

(case e & test-result-pairs default?)

Macro. Constant-time dispatch on compile-time literal test values; last arg is the default, throws when absent and unmatched.

condp

(condp pred expr & clauses)

Macro. (condp pred expr ...) — first clause where (pred test-val expr) is truthy.

ns

(ns name & clauses)

Macro. Names the current namespace and processes :require/:refer/:as clauses.

require

(require & specs)

Loads namespaces from *load-path* (name → path: . becomes /, - becomes _). Supports [ns :as alias] and [ns :refer [syms]].

comment

(comment & body)

Macro. Ignores its body, returns nil.

time

(time expr)

Macro. Evaluates expr, prints elapsed milliseconds, returns the value.

with-out-str

(with-out-str & body)

Macro. Evaluates body capturing *out*; returns what it printed as a string.

delay

(delay & body)

Macro. Wraps body in an unrealized Delay: deref/force evaluates once and caches.

lazy-seq

(lazy-seq & body)

Macro. Wraps body in an unrealized lazy sequence; realized once on first seq access.