public
Last active

Clojure: define the unless function and use in examples

  • Download Gist
unless.clj
Clojure
1 2 3 4 5 6 7 8 9
(defn unless [test expr] (if-not (eval test) (eval expr)))
 
(prn (unless (odd? 11) (str "it's good to be " 11)))
(prn (unless (odd? 12) (str "it's good to be " 12)))
 
(defn only-if-even [x] (unless (odd? x) (str "it's good to be " x)))
 
(prn (str 6 " " (only-if-even 6)))
(prn (str 5 " " (only-if-even 5)))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.