Clojure keyword argument default depending on other keyword argument? -
I'm trying to get an optional keyword parameter that depends on other alternative keyword parameters for its value.
Example function:
(defan printab [& amp;;: keys [ab]: or {: a 5: b 200}}] (println "a is "A" b is "b))
The default value of The function below, the way I have hoped, does not work: : b
should be : a
. Is there a way to do this within the defn
macro, or should I give a to handle this behavior?
(defan print & [: keys [ab]: or {: a 5: ba}] (println "a is" a "b is" b)
< P> It is possible to get one without using it. One part of the problem is the colon prefix in the map of default, which should be left. I think you will also need a reference to the entire map of the arguments to work. The following appears to be:
(defn printab [& amp;;: keys [ab]: as mi: or {a 5b (: 5m}}}] (println "A" a "b is" b "))
Comments
Post a Comment