Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Clojure

Idiom #252 Conditional assignment

Assign to the variable x the string value "a" if calling the function condition returns true, or the value "b" otherwise.

(def x (if condition
         "a"
         "b"))

In Clojure values are truthy/falsy
x := (if condition() then "a" else "b");

New implementation...
< >
programming-idioms.org