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 : b should be : a . Is there a way to do this within the defn macro, or should I give a to handle this behavior?

The function below, the way I have hoped, does not work:

  (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

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -