Skip to content
Turtle Kitty edited this page Aug 9, 2015 · 2 revisions

cond

This is a general conditional operator. It accepts a list of alternating predicates and consequents, executing the first consequent for which the corresponding predicate returns true. It accepts the default: keyword to provide behavior in which no predicate matches (the default is to throw an error when this happens).

(fun foo (x)
    (cond
        (= x 0) 'foo
        (= x 1) 'bar
        (= x 2) (+ x x x)
        default: (* x x)))

(foo 0) -> 'foo
(foo 1) -> 'bar
(foo 2) -> 6
(foo 3) -> 9
Clone this wiki locally