Skip to content
TurtleKitty edited this page May 11, 2019 · 3 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 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
Clone this wiki locally