Hi All,

I've found extending-protocol to hold on to a references to records when
they're redefined.

example> (defprotocol ToExtend
  (foo [this]))
ToExtend

example> (defrecord Extender1 [])
example.Extender1

example> (extend-protocol ToExtend Extender1 (foo [this] "extender1"))
nil

example> ToExtend
{:impls {example.Extender1 {:foo #<example$eval3465$fn__3466
example$eval3465$fn__3466@5549f0e>}}, :on-interface example.ToExtend, :on
example.ToExtend, :sigs {:foo {:doc nil, :arglists ([this]), :name foo}},
:var #'example/ToExtend, :method-map {:foo :foo}, :method-builders
{#'example/foo #<example$eval3417$fn__3418 example$eval3417$fn__3418@71a67fe
>}}

example> (count (:impls ToExtend))
1

example> (defrecord Extender1 [a])
example.Extender1

example> (foo (Extender1. "a"))
No implementation of method: :foo of protocol: #'example/ToExtend found for
class: example.Extender1
  [Thrown class java.lang.IllegalArgumentException]

example> (extend-protocol ToExtend Extender1 (foo [this] "extender1a"))
nil
example> (foo (Extender1. "a"))
"extender1a"

example> ToExtend
{:impls {example.Extender1 {:foo #<example$eval3519$fn__3520
example$eval3519$fn__3520@4d86d315>}, example.Extender1 {:foo
#<example$eval3465$fn__3466 example$eval3465$fn__3466@5549f0e>}},
:on-interface example.ToExtend, :on example.ToExtend, :sigs {:foo {:doc nil,
:arglists ([this]), :name foo}}, :var #'example/ToExtend, :method-map {:foo
:foo}, :method-builders {#'example/foo #<example$eval3417$fn__3418
example$eval3417$fn__3418@71a67fe>}}

example> (count (:impls ToExtend))
2


You'll notice in the map returned after the second (extend-protocol) that
:impls has example.Extender1 listed twice. I assume this is because they're
different records, though the fact that they share the same name is
confusing (hence the example of the exception being thrown).


A few questions:
 - Is this expected behaviour?
 - If so, why? It feels "odd" to have two classes of the same name (type
even?) act differently


In the other examples of extend-protocol being used
(compojure.response/Renderable) types far less likely to be redefined are
being used, so perhaps this is only to be used with types that change less?
If that is the case then how does one achieve what I'm trying to do; extend
Renderable to support my own types being passed to it without Renderable
acting on my previous types?

Cheers,

mike

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