-
Notifications
You must be signed in to change notification settings - Fork 2
cond
TurtleKitty edited this page May 11, 2019
·
3 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 else: keyword to provide behavior in which no predicate matches (the standard default is to throw an error when this happens).
(proc foo (x)
(cond
(= x 0) 'foo
(= x 1) 'bar
(= x 2) (+ x x x)
else: (* x x)))
(foo 0) ; 'foo
(foo 1) ; 'bar
(foo 2) ; 6
(foo 3) ; 9