tur/macros

stdlib/macros.tur
defmacro

cond

(cond [& clauses])

variadic conditional branching via nested if chains.

& clauses -- alternating test/expression pairs, with optional :else at end

Since: Phase 7

defmacro

when

(when [test body])

evaluate body only if test is truthy.

testthe condition to evaluate
bodyexpression to evaluate when test is truthy

Since: Phase 7

defmacro

unless

(unless [test body])

evaluate body only if test is falsy.

testthe condition to evaluate
bodyexpression to evaluate when test is falsy

Since: Phase 7

defmacro

must!

(must! [expr])

unwrap an option or result value, panicking if absent.

expran option or result expression to unwrap

Since: Phase R4

defmacro

must-msg!

(must-msg! [expr msg])

unwrap an option or result value with a custom panic message.

expran option or result expression to unwrap
msgthe message to panic with if the value is absent

Since: Phase R4

defmacro

ignore!

(ignore! [expr])

explicitly discard a result value.

exprthe expression whose value should be discarded

Since: Phase R6

defmacro

do-m

(do-m [& forms])

monadic do-notation using .bind dispatch.

& forms -- alternating variable/monadic-action pairs followed by a body;
the last form is the body expression

Since: Phase HKT H6

defmacro

for

(for [binding-vec & body])

monadic comprehension with optional guards.

binding-vecflat vector of alternating var/collection pairs,
with optional :when guard clauses interspersed
& body -- the body expression(s) to lift into the monad

Since: Phase HKT H7

defmacro

assert!

(assert! [condition])

Phase C1: Runtime contract macros

conditionthe boolean expression to check

Since: Phase C1

defmacro

assert-msg!

(assert-msg! [condition msg])

unconditional sanity check with custom panic message.

conditionthe boolean expression to check
msgthe message string to use when panicking

Since: Phase C1

defmacro

require!

(require! [condition])

precondition check at function entry, panics with "Precondition failed" if false.

conditionthe boolean precondition to enforce

Since: Phase C1

defmacro

require-msg!

(require-msg! [condition msg])

precondition check with custom panic message.

conditionthe boolean precondition to enforce
msgthe message string to use when panicking

Since: Phase C1

defmacro

ensure!

(ensure! [condition])

postcondition check, panics with "Postcondition failed" if false.

conditionthe boolean postcondition to enforce

Since: Phase C1

defmacro

ensure-msg!

(ensure-msg! [condition msg])

postcondition check with custom panic message.

conditionthe boolean postcondition to enforce
msgthe message string to use when panicking

Since: Phase C1

defmacro

invariant!

(invariant! [obj predicate])

check a structural invariant on a value, panics with "Invariant failed" if false.

objthe value to check
predicatea single-argument function that returns true if the invariant holds

Since: Phase C1

defmacro

invariant-msg!

(invariant-msg! [obj predicate msg])

check a structural invariant with custom panic message.

objthe value to check
predicatea single-argument function that returns true if the invariant holds
msgthe message string to use when panicking

Since: Phase C1

defmacro

curry

(curry [f])

convert a 2-argument function to its curried form.

fa 2-argument function

Since: CY3

defmacro

doc

(doc [name])

print documentation for a function, macro, or struct at the REPL.

namesymbol whose documentation to display

Since: Phase D1 (auto-docs)