Clojure keyword argument default depending on other keyword argument? -
i trying optional keyword parameter depends on optional keyword parameter value.
example function:
(defn printab [& {:keys [a b] :or {:a 5 :b 200}}] (println "a is" "b is" b))
i want default value of :b
value of :a
. there way within defn
macro, or need create let
binding handle behavior?
the below function not work way hoped:
(defn printab [& {:keys [a b] :or {:a 5 :b a}] (println "a is" "b is" b))
it's possible accomplish without using let. part of problem colon prefixes in map of defaults, should omitted. think you'll need reference whole map of arguments work. next appears it:
(defn printab [& {:keys [a b] :as m :or {a 5 b (:a m 5)}}] (println "a is" "b is" b))
clojure
No comments:
Post a Comment