Forgive me if I'm misunderstanding, but you don't need to import a
protocol to use it.  If you need to actually get ahold of the protocol
(say, to implement another deftype/defrecord), you can just use
`require` or `use` to get ahold of it:

    (ns stuff
      (:use [com.example-ns :only [IFoo])
      (:import [com.example-ns Foo]))

Then inside that ns, you can just refer to IFoo and Foo.  I'm
surprised that the underscored version of the import works for a
protocol - I've never seen anyone use that before.  I wonder if it's
just an oversight on my part or if that's a non-recommended use of
import...

Micah Martin just showed me a behavior very similar to this recently,
and since then I'd been thinking of protocols more like normal Clojure
data structures, and deftypes/defrecords more like Java classes.
Confirming that, if I look at the type of IFoo, it is a
clojure.lang.PersistentArrayMap, and Foo is a java.lang.class.

Colin



On Feb 5, 1:20 pm, Shantanu Kumar <kumar.shant...@gmail.com> wrote:
> When I declare using defprotocol:
>
> (defprotocol IFoo
>   (bar [this] "some doc"))
>
> and then using deftype:
>
> (deftype Foo
>   IFoo
>     (bar [this] "from Foo::bar"))
>
> I noticed there is an interesting difference in the way I need to
> import them in another namespace:
>
>   (:import
>     (com.example_ns IFoo)  ; importing Foo here gives error (notice
> underscore)
>     (com.example-ns Foo))  ; importing IFoo here gives error (notice
> dash)
>
> Can somebody explain the rationale behind this? The dash character is
> not valid inside a Java package names so a protocol not supporting it
> is understandable. But when I deftype something, is it not supposed to
> be consumed from within Java-the-language?
>
> Shantanu

-- 
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