-
Notifications
You must be signed in to change notification settings - Fork 4
cond
Turtle Kitty edited this page Aug 9, 2015
·
2 revisions
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