Well, this is certainly a possibility. Especially if I do it at
compilation time, I can put the match functions for each class into an
array, and then combine them by climbing the class hierarchies.
Phil
"Jim - FooBar();" writes:
> On 02/08/13 12:46, Jim - FooBar(); wrote:
>> or programmatical
You could spice things a bit up:
(defn extend-to
[protocol & class-impl-mappings]
(doseq [[class impl] (partition 2 class-impl-mappings)]
(extend class protocol impl)))
(extend-to PThree
Long{:hello long-hello}
Integer {:hello long-hello}
Number
"Meikel Brandmeyer (kotarak)" writes:
>> Sure, I understand why it's not working! I just don't know how to fix it.
>>
>>
> Plain old functions:
>
> (defn number-hello
> [n]
> (when (= n 10)
> "hello"))
>
> (defn long-hello
> [n]
> (if (= n 5)
> "goo
On 02/08/13 12:46, Jim - FooBar(); wrote:
or programmatically emit identical extension points for all
subinterfaces/subclasses
;;adopted from clojure/core/protocols.clj
(def ^:private co-stub
'(run [this text]
(if (instance? edu.stanford.nlp.pipeline.Annotation text)
(do (.annotate thi
On 02/08/13 12:24, Phillip Lord wrote:
"Jim - FooBar();" writes:
your extension point on Number is never fired because 10 is a Long.
Sure, I understand why it's not working! I just don't know how to fix it.
there is nothing to fix in this particular example...everything works
as expected.
Hi,
Am Freitag, 2. August 2013 13:24:07 UTC+2 schrieb Phillip Lord:
>
> "Jim - FooBar();" > writes:
> > your extension point on Number is never fired because 10 is a Long.
>
> Sure, I understand why it's not working! I just don't know how to fix it.
>
>
Plain old functions:
(defn number-he
"Jim - FooBar();" writes:
> your extension point on Number is never fired because 10 is a Long.
Sure, I understand why it's not working! I just don't know how to fix it.
> Generally speaking extending protocols to interfaces is not
> suggested...
I'm extending an API which is interface driven
Moreover, if you're going to extend a particular protocol to many types,
it's better to use 'extend-protocol' which expands to a bunch of
'extend-type' forms...if you need a point of reference I recently
finished extending a 'DataSet' protocol to all clojure/java
data-structures. YOu can find
your extension point on Number is never fired because 10 is a Long.
Generally speaking extending protocols to interfaces is not
suggested...I've been bitten a couple of times in particular whenever
I'm extending to 2 different interfaces that *are* related...You can
certainly do it but you have
I want to use extend-type to support a protocol both on a class and it's
subclasses. But I don't know how to do a superclass call. So for
instance, with this code
(defprotocol PThree
(hello [this]))
(extend-type
Number PThree
(hello [this]
(if (= 10 this)
"hello")))
10 matches
Mail list logo