Flow Control and Conditionals

If

if takes a conditional expression and evaluates the true expression if the condition is true, or the false expression otherwise.

(if (condition) (if true expression) (if false expression))

cond

The cond statement (switch in Javascript) takes condition-expression pairs and an optional default expression. The default expression is nothing but the last condition set to true.

(cond (condition1) (expression1) (condition2) (expression2) ... (optional default expression))

Example:

(cond

(number? x) (console.log "numbers are ok")

(string? x) (console.log "strings are ok")

(boolean? x) (console.log "booleans are ok")

true (console.log "This type is NOT ok"))

when

The when statement evaluates a set of expressions passed as it arguments when the condition is true.

(when (condition) (expression1) (expression2) ...)

unless

The unless statement evaluates a set of expressions passed as it arguments when the condition is false.

(unless (condition) (expression1) (expression2) ...)

empty?

Returns true if the given array is empty. Returns false otherwise.

(empty? (array))

results matching ""

    No results matching ""