Alan Malloy <[email protected]> writes:
Hi Alan,
>> IMHO, `extenders' should return also types implementing the protocol
>> interface directly [i.e., deftypes and defrecords], so that
>>
>> (extends? P T) <=> (some #(= % T) (extenders P))
>>
>> holds.
>
> You're entitled to that humble opinion, but it's not really possible
> with any kind of reasonable performance. When you implement the
> protocol interface directly, no machinery in clojure.core gets
> involved at all - you just define a class that implements an
> interface. For `extenders` to be able to list Java classes that
> implement the interface directly, it would have to walk through every
> class loaded in the JVM and check its implemented-interfaces.
>
> Of course, you could make it almost-work, by having deftype/defrecord
> emit some special code for hooking into extenders whenever you define
> a class in Clojure,
That's what I had in mind. deftype/defprotocol could just alter the
:impls of the protocol, just like `extend' does.
> but then it would only work for classes defined within Clojure, and
> not for Java classes that implement Clojure's interfaces/protocols.
Well, yes.
> Frankly I think that's worse than just limiting it to "dynamic"
> extenders.
I'd prefer if it was limited to "extenders that extend within clojure",
because that seems to be the more common case. My use case for
`extenders' was my API docs generator, where I'd like to add to every
protocol description the types that extend that protocol.
So basically, I see 3 options:
1) rename `extenders' to `dynamic-extenders' (or something like that)
to get rid of the extends?/extenders inconsistency
2) remove `extenders' completely (can anyone think of any use case for
it in its current incarnation that is important enough that it
justifies a core function instead of using (keys (:impls protocol))
directly?)
3) make deftype/defrecord alter the :impls just like `extend' does and
document the limitation concerning implementing protocol interfaces
in java explicitly in the `extenders' docstring
I'm happy to provide a patch for either option.
Bye,
Tassilo
--
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