Simpler to just use the field names which are already bound, rather
than constructing keywords out of them and calling them with juxt:
(defmacro defrecord-withstr [name fields columns include?]
(let [displayed (if include? columns (remove (set columns) fields))]
`(defrecord ~name ~fields
Object
(toString [_#]
(clojure.string/join " " [~@displayed])))))
On Oct 18, 9:25 am, "Marshall T. Vandegrift" <[email protected]>
wrote:
> Dusan <[email protected]> writes:
> > (symbol(str "(str (:" % " " vv "))"))
>
> This expression is the (immediate) problem child. You are producing a
> symbol which contains literal space and parenthesis characters embedded
> in it. When you print out the macro-expansion, it looks fine, but the
> actual forms generated contain that weird symbol instead of the expected
> list structure.
>
> You do have other problems though --
>
> - A symbol prefixed with a colon is just a symbol prefixed with a
> colon, not a keyword. You need to use the `keyword' function to
> create a keyword from a symbol or string.
>
> - Instead of calling `gensym' directly, it's probably easier to just
> use autogensyms in this sort of situation.
>
> For fun, here's a (hopefully) more idiomatic version:
>
> (defmacro defrecord-withstr [name fields columns include?]
> (let [displayed (->> (if include? columns (remove (set columns) fields))
> (map keyword))]
> `(defrecord ~name ~fields
> Object
> (toString [this#]
> (str/join " " ((juxt ~@displayed) this#))))))
>
> -Marshall
--
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