Optimize .addComponent?

13 views
Skip to first unread message

Antonio Recio

unread,
Jun 23, 2011, 8:24:47 AM6/23/11
to clo...@googlegroups.com
I would like to use only one time ".addComponent" and don't repeat it each time that I need to add something. How I can do it? Perhaps with doto? Are there other way? It is possible to optimize it more?

(defn -init [this]
  (let [app this]
    (.setMainWindow this
      (doto (Window. "Test application")
        (.addComponent (Label. "Hello!"))
        (.addComponent (Button. "button"))))))

Laurent PETIT

unread,
Jun 23, 2011, 8:43:34 AM6/23/11
to clo...@googlegroups.com
If your code does not grow beyond what you show us, it seems like a
good compromise.

If you want to be more DRY, here's my take:

(defn add-components! [composite components]
(doseq [component components] (.addComponent composite component)))

(defn -init [this]
(let [app this]
(.setMainWindow this
(doto (Window. "Test application")

(add-components! (Label. "Hello!") (Button. "button"))))))

2011/6/23 Antonio Recio <amdx...@gmail.com>:

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

Antonio Recio

unread,
Jun 23, 2011, 9:08:01 AM6/23/11
to clo...@googlegroups.com
I obtain an error:
javax.servlet.ServletException: java.lang.IllegalArgumentException: Wrong number of args (3) passed to: vapp$add-components-BANG-

java.lang.IllegalArgumentException: Wrong number of args (3) passed to: vapp$add-components-BANG-

Laurent PETIT

unread,
Jun 23, 2011, 9:12:55 AM6/23/11
to clo...@googlegroups.com
oops, def of add-components should read (defn add-components!
[composite & components] of course ...

2011/6/23 Laurent PETIT <lauren...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages