Hi,

On Dec 3, 4:46 pm, lazy1 <miki.teb...@gmail.com> wrote:

> >> What is the right way to do this?
> > (defn new-container
> >  [type]
> > (.newInstance (*containers* type)))
> > (defmacro new-container [type]
> > `(new ~(*containers* type)))
>
> Thanks! These are both great and also very educational.
>
> The reason for this coding style is that I'm writing a wrapper around
> webdriver, and I'd like a factory function to create a driver for a
> specific browser.
> (def *drivers* {
>       :firefox FirefoxDriver
>       :ie InternetExplorerDriver })
>
> (defn new-driver
>   "create new driver"
>   [browser]
>   (.newInstance (*drivers* browser)))

And if nothing else works: there is always ye olde wrapper.

(defn firefox
  []
  (FirefoxDriver.))

; This allows also for more elaborate setup if needed...
(defn internet-explorer
  []
  (doto (IEDriver.)
    (.setSomeOption 1)
    (.andSomeOther "2")))

(def *drivers* {:firefox firefox :ie internet-explorer})

(defn new-driver
  [browser]
  ((*drivers* browser)))

Sincerely
Meikel

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to