If I run the following code in the REPL
(let [f '.startsWith] (f "abab" "a"))
it is evaluated to "a" instead of 'true'. Could someone please explain me this surprising result?
Actually, the real code, I want to make work is the following.
(defn set-up-bean! [bean functions-and-parameters]
(doseq [[f p] functions-and-parameters]
(f bean p))
(.init bean))
What I want to achieve is, to make the following two function calls do the same thing.
(set-up-bean! bean [['.setMember "a"]])
and
(do
(.setMember bean "a")
(.init bean))
One conventional approach is to use an anonymous function
(let [f (fn [a b] (.startsWith ^String a ^String b))] (f "abab" "a"))
...as this lets you type-hint parameters as-needed. You might also consider memfn:
(let [f (memfn startsWith String)] (f "abab" "a"))
In any event -- dot notation is syntactical sugar for interop, rather than providing real callable functions.
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