On Tue, Dec 10, 2013 at 4:25 AM, Phillip Lord
<phillip.l...@newcastle.ac.uk>wrote:

> (defn ^IRI iri
>   [name]
>   (cond
>    (instance? String name)
>    (IRI/create ^String name)
>    (instance? java.net.URL name)
>    (IRI/create ^java.net.URL name)
>    (instance? java.io.File name)
>    (IRI/create ^java.io.File name)))
>
> which is a lot longer and, well, just not very nice. I could make this
> neater with a macro -- something like...
>
> (with-types [String, URL, File]
>    (IRI/create name))
>
> which would expand into the cond form above. But the instance? checks
> seem not ideal. Is there a better solution?
>

You could create and extend an "IIriCreate" protocol to String, URL, and
File.

I'd like to point out that Java doesn't provide a clean way to handle this
either.

-- 
-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to