Hi all,
I need a macro to basically outputs this:
(macroexpand '(chain-field-queries record "location" "name" "country"))
(. (. (. record (field "location")) (field "name")) (field "country"))
Which chains method calls on a java object. e.g.
record.field("location").field("name").field("country"). etc...
so far so good. I though I could modify the .. macro for this:
(defmacro chain-field-queries
([x form] `(. ~x (field ~form)))
([x form & more] `(chain (. ~x (field ~form)) ~@more)))
However, this results in
(macroexpand '(chain-field-queries record "location" "name" "country"))
(. (. (. record (user/field "location")) (user/field "name")) (user/field
"country"))
Now, I have a macro which produces the output above (without the namespace
qualifier) but it looks odd. Is there an easier/more idiomatic way?
(defmacro chain-field-queries
([x form] (let [field# 'field]
`(. ~x (~field# ~form))))
([x form & more] (let [field# 'field]
`(chain (. ~x (~field# ~form)) ~@more))))
Cheers
Andreas
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en