Globals in ControlMacros.carp
-->
Macro
(--> :rest forms)
threads the first form through the following ones, making it the last argument.
Example:
(--> 1
(- 10)
(/ 45)
) ; => 5
->
Macro
(-> :rest forms)
threads the first form through the following ones, making it the first argument.
Example:
(-> 1
(- 10)
(* 5)
) ; => -45
case
Macro
(case form :rest branches)
takes a form and a list of branches which are value and operation
pairs. If a value matches (or any in a list of values preced by :or
), the
operation is executed. It takes a catch-all else branch that is executed if
nothing matches.
Example:
(case (+ 10 1)
10 (println* "nope")
11 (println* "yup")
(:or 12 13) (println* "multibranch, but nope")
(println* "else branch")
)
doto
Macro
(doto thing :rest expressions)
Evaluates thing
, then calls all of the functions on it and
returns it. Useful for chaining mutating, imperative functions, and thus
similar to ->
. If you need thing
to be passed as a ref
into expressions
functions, use doto-ref
instead.
(let [x @"hi"]
@(doto &x
(string-set! 0 \o)
(string-set! 1 \y)))
doto-ref
Macro
(doto-ref thing :rest expressions)
Evaluates thing
, then calls all of the functions on it and
returns it. Useful for chaining mutating, imperative functions, and thus
similar to ->
. If you need thing
not to be passed as a ref
into
expressions
functions, use doto
instead.
(doto-ref @"hi"
(string-set! 0 \o)
(string-set! 1 \y))
ignore-do
Macro
(ignore-do :rest forms)
Wraps side-effecting forms
in a do
, ignoring all of their results.
In other words, executes forms
only for their side effects.