Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case cases in Clojure

Besides the constant time dispatch of case, what could be other points leading me to use case instead of cond condp?


1 Answers

  1. Assuming that you really are dealing with compile-time constants, case semantically conveys the nature of your condition better than cond or condp.
  2. case is more concise than cond or condp.

Example:

(cond
  (= foo 1) :one
  (= foo 2) :two
  (= foo 3) :three)

(condp = foo
  1 :one
  2 :two
  3 :three)

(case foo
  1 :one
  2 :two
  3 :three)

I can't comment on any performance aspects, but as always, that should be the least of your considerations.

like image 196
Sam Estep Avatar answered Jul 11 '26 05:07

Sam Estep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!