When calling a Clojure function from Java, what's the best way to specify named arguments to the function?
I have the following function:
(defn myFn [a b & {:keys [c d] :or {c 1 d 2}}]
; do something
)
And I currently call it from Java with lines like this:
IFn myFn = Clojure.var("my.namespace", "myFn");
myFn.invoke(5, 6, Clojure.read(":c"), 7, Clojure.read(":d"), 8);
I find the Clojure.read... parts of the above statement verbose. Is there a simpler way to make this call?
The question is not about how to pass named argument, but how to create keywords in Java code:
import clojure.lang.Keyword;
// others omitted...
myFn.invoke(5, 6, Keyword.find("c"), 7, Keyword.find("d"), 8);
Clojure.read would be considered too cumbersome for the task and too dangerous as it can read in any code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With