Re: Type hint using protocol

2015-09-08 Thread William la Forge
Frances, I have two implementations of INode, record MapNode and record VectorNode, which are defined in other files. Also, I get a syntax method when calling new-node without the leading dot when using defprotocol: java.lang.IllegalArgumentException: No single method: newNode of interface: a

Re: Type hint using protocol

2015-09-08 Thread William la Forge
aatree.nodes.INode always gives me a class not found. But switching to definterface does it for me. Many thanks! On Tuesday, September 8, 2015 at 3:16:56 PM UTC-4, Andrey Antukh wrote: > > > > On Tue, Sep 8, 2015 at 9:31 PM, William la Forge > wrote: > >> I'm finally looking at warn on reflecti

Re: Type hint using protocol

2015-09-08 Thread Francis Avila
I don't quite understand why you are not calling the Protocol method as a function, i.e. (new-node this t-2 lev l r c) (no leading dot on new-node). I also don't see anything which actually *implements* INode. Note that the meaning of "method" in "Protocol method" is not the same as in "Java

Re: Type hint using protocol

2015-09-08 Thread Andrey Antukh
On Tue, Sep 8, 2015 at 9:31 PM, William la Forge wrote: > I'm finally looking at warn on reflection. Everything is going fine except > in the nodes.clj file where I define a protocol, INode, with a method, > new-node and then try to call that method from a function, revise. > > I'm using Clojure

Re: Type hint using protocol

2015-09-08 Thread William la Forge
I'm finally looking at warn on reflection. Everything is going fine except in the nodes.clj file where I define a protocol, INode, with a method, new-node and then try to call that method from a function, revise. I'm using Clojure 1.7.0 and the file is https://github.com/laforge49/aatree/blob/m

Re: Type hint using protocol

2014-01-12 Thread bob
Cool! learn a lot from you. thanks again. On Sunday, January 12, 2014 10:22:30 PM UTC+8, Jim foo.bar wrote: > > or even nicer: > > (map [this f] > (let [^DBIterator iterator (doto (.iterator db) .seekToFirst)] > (clojure.core/map #(apply f %) (iterator-seq iterator > > Ok I will stop n

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
On 12/01/14 14:15, Jim - FooBar(); wrote: (map [this f] (let [^DBIterator iterator (.iterator db)] (.seekToFirst iterator) (clojure.core/map #(apply f %) (iterator-seq iterator or even nicer: (map [this f] (let [^DBIterator iterator (doto (.iterator db) .seekToFirst)] (clojure.core/

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
On 12/01/14 13:59, Jim - FooBar(); wrote: On 12/01/14 13:57, bob wrote: Thanks for the big help, I treated the protocol as interface. :) no worries :) I was also surprised to see that you are type-hinting the clojure.lang.Atom...why would you do that? from what I can see you are only using `

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
On 12/01/14 13:57, bob wrote: Thanks for the big help, I treated the protocol as interface. :) no worries :) I was also surprised to see that you are type-hinting the clojure.lang.Atom...why would you do that? from what I can see you are only using `reset!` and `swap!`...I doubt that you are

Re: Type hint using protocol

2014-01-12 Thread bob
Thanks for the big help, I treated the protocol as interface. :) On Sunday, January 12, 2014 9:38:12 PM UTC+8, Jim foo.bar wrote: > > It is not compiling because it cannot find the function...either fully > qualify it like in my previous email or change your ns declaration to > something like:

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
oops (set! *clojure.core*/*warn-on-reflection* true) instead of (set! *user*/*warn-on-reflection* true) On 12/01/14 13:52, Jim - FooBar(); wrote: there you go: (defprotocol IBark (bark [this])) (in-ns 'other) (set! user/*warn-on-reflection* true) (clojure.core/defrecord Dog [] user/IBa

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
there you go: (defprotocol IBark (bark [this])) (in-ns 'other) (set! user/*warn-on-reflection* true) (clojure.core/defrecord Dog [] user/IBark (bark [_] (clojure.core/println "WOOF!"))) (def d (Dog.)) (user/bark d) ;;NO reflection (.bark d) ;;reflection it should be obvious now :) Jim

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
It is not compiling because it cannot find the function...either fully qualify it like in my previous email or change your ns declaration to something like: [cqrs.storage :as stora] and then simply use stora/ret-value, stora/write, stora/write-batch Jim On 12/01/14 13:26, bob wrote: If I

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
Basically you're falling into the trap of thinking of protocols as if they were interfaces...protocols do not represent a specific data-type but rather a contract. That contract can then be extended to any concrete type. But you always need to go through the protocol...what I do when I have man

Re: Type hint using protocol

2014-01-12 Thread bob
If I remove the dot, it cannot be compiled. can you give an example? On Sunday, January 12, 2014 9:22:00 PM UTC+8, Jim foo.bar wrote: > > I am suspecting you are calling the protocol implementations via the `.` > form, whereas you should be going via the protocol itself (whatever > namespace tha

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
Haha I knew it Instead of using .ret-value and .write use cqrs.storage/ret-value and cqrs.storage/write...Also in your ns declaration you don't really need to bring in the protocol. YOu can bring in the functions it defines :) Jim On 12/01/14 13:22, bob wrote: Sure, here has a protoco

Re: Type hint using protocol

2014-01-12 Thread bob
Sure, here has a protocol named Store , and will be used in this file at line #14, the compiler tells me the warnings, forgo

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
On 12/01/14 13:07, Jim - FooBar(); wrote: On 12/01/14 13:04, bob wrote: Exactly! the compiler throws the reflection warnings, I want to type hint for the input parameters to eliminate the warnings. you must be doing something wrong as a pure protocol based implementation that doesn't involve

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
On 12/01/14 13:04, bob wrote: Exactly! the compiler throws the reflection warnings, I want to type hint for the input parameters to eliminate the warnings. you must be doing something wrong as a pure protocol based implementation that doesn't involve interop, shouldn't exhibit reflection...W

Re: Type hint using protocol

2014-01-12 Thread bob
Exactly! the compiler throws the reflection warnings, I want to type hint for the input parameters to eliminate the warnings. On Sunday, January 12, 2014 8:58:14 PM UTC+8, Jim foo.bar wrote: > > In order to do that you would have to reach to the interface behind the > protocol...observer this:

Re: Type hint using protocol

2014-01-12 Thread Jim - FooBar();
In order to do that you would have to reach to the interface behind the protocol...observer this: user=> (defprotocol P (f1 [_] nil)) P user=> P {:on-interface user.P, :on user.P, :sigs {:f1 {:doc "YES!", :arglists ([_]), :name f1}}, :var #'user/P, :method-map {:f1 :f1}, :method-builders {#'u

Type hint using protocol

2014-01-12 Thread bob
Hi, Is it possible to add type hint (the type is protocol) to funs? for example: (defprotocol IProtocol (f1 [])) can we define fn like this? (defn ftest [^IProtocol arg] (.toString arg)) -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To p