Boolean operators (and, or) in Clojure -


here quote http://www.braveclojure.com/:

clojure uses boolean operators or , and. or returns either first truthy value or last value. and returns first falsey value or, if no values falsey, last truthy value.

why build language? how come across use cases it?

it bit different other languages, handy default values. example:

(defn print-it [x]    (println (or x :unknown)))  > (print-it 5) 5  > (print-it "hi") hi  > (print-it false) :unknown  > (print-it nil) :unknown 

so normal value 5 or "hi", result of or expression supplied value. if value nil (or false), default value :unknown returned.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -