> (defrecord Foo [properties]
> Fooable
> (foo [f]
> (let [s (java.util.HashSet.)]
> (doto s
> (doseq [p properties] (.add s p))))))
>
> When I load/reload the above code in the repl I get this error
>
> <CompilerException java.lang.IllegalArgumentException: doseq requires a
> vector for its binding (config.clj:22)>
The problem is the way you're calling doto, not the defrecord. If you
macroexpand the doto, you'll get something like:
(clojure.core/let [G__1646 s] (doseq G__1646 [p properties] (.add s p)) G__1646)
doto puts your 's' as the first argument in all the forms. So the
first argument to doseq is no longer your binding vector, and so doseq
doesn't like it.
> If I change my defrecord to,
>
> (defrecord Foo [properties]
> Fooable
> (foo [f]
> (let [s (java.util.HashSet.)]
> (doto s (add-props s properties)))))
This macroexpands to something like:
(clojure.core/let [G__1649 s] (add-props G__1649 s properties) G__1649)
That's not quite what you want either, because the set gets passed to
add-props twice.
You want:
(defrecord Foo [properties]
Fooable
(foo [f]
(let [s (java.util.HashSet.)]
(doto s (add-props properties)))))
Or, more concisely:
(defrecord Foo [properties]
Fooable
(foo [f]
(doto (java.util.HashSet.) (add-props properties))))
But there's also a typo in your add-props: the (.add p) needs to
become (.add s p)
Then again, you may just want (set properties) instead of the whole
doto thing, to save yourself the effort!
--
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