I’m working on some java library wrapper.
We have some object with methods and can invoke them with (.method object ...). I want to create more convenient api with number of functions (method object ...).
I wrote a simple macro:
(defmacro ^{:private true} gen-method [method & argv]
`(def ~method (memfn ~method ~@argv)))
Now I can invoke (gen-method charAt i) for example and after that I can use (charAt "string" 1).
But I have a lot of method to generate and want to use something like:
(map #(gen-method (-> %1 name symbol arg)) [:charAt :substring ...])
But this is not working. Next example is not working too:
(map #(let [fname (-> %1 name symbol)] (gen-method fname arg)) [:charAt :substring ...])
What I need to change in macro or add something for correct behaviour ?
Thanks.
You will have to take the
mapoperation inside the macro itself as themapoperation should happen at compile time i.e form expanding time and not at runtime.Something like below: