Your question doesn't specifically ask about multiple vars, but if you did want this defaulting for more than one var the idiomatic way to do it is to use destructuring on map with :or
defaults.
e.g. Take this function that takes a map argument m
, the expected map has keys of :a
, :b
, & :c
but if :b
and/or :c
are not supplied then the defaults are taken from the :or
clause
(defn foo [m]
(let [{:keys [a b c], :or {b 100 c 200}} m]
(println "a:" a)
(println "b:" b)
(println "c:" c)))
user> (foo {:a 1 :b 2})
a: 1 ; no default, use supplied value
b: 2 ; value supplied, default ignored
c: 200 ; no value supplied, use default from :or
nil