Reading — step 1 of 5
Learn
~1 min readFlow and Recursion
Conditionals are expressions — they return values.
if takes a test, then-branch, optional else-branch:
(if (> x 0)
"positive"
"non-positive")
cond for multiple branches:
(cond
(>= score 90) "A"
(>= score 80) "B"
(>= score 70) "C"
:else "F")
:else is just the keyword :else — it's truthy and serves as the default. You could use true or :default instead; :else is convention.
when is if with no else and an implicit do for multiple statements:
(when (= status "ready")
(log-it "starting")
(start-process))
Falsy values: only false and nil. Empty collections, 0, "" are all truthy.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…