Re: Protocols and Types

2010-03-03 Thread Konrad Hinsen
On 03.03.2010, at 16:05, Andrea Tortorella wrote: > given that a protocol is represented as a simple map, which is the > way to know if something is infact a protocol. I don't think that is possible without relying on undocumented characteristics that are likely to change. What do you need this

Re: Protocols and Types

2010-03-03 Thread Andrea Tortorella
I'm not on my machine so i'cant experiment, i tried on #clojure with clojurebot but it's not 1.2, so i ask here, given that a protocol is represented as a simple map, which is the way to know if something is infact a protocol. Or suppose i want to add a function that works on protocols how can i

Re: Protocols and Types

2010-03-03 Thread Meikel Brandmeyer
Hi, On Mar 3, 2:43 pm, Andrea Tortorella wrote: You have to use some instance of T. > (extends? P T) > ;==> nil (extends? P some-t) will return false, because you don't call extend explicitly. > (satisfies? P T) > ;==> nil (satisfies? P some-t) will return true. > (extenders P) > ;==>nil S

Re: Protocols and Types

2010-03-03 Thread Stuart Halloway
Hi Andrea, You need to make two little changes: (1) satisfies? is a predicate about instances, not types, and (2) the extend predicates check for explicit extension: (defprotocol P (foo [x])) (deftype T []) (extend ::T P {:foo (fn [] "dummy")}) (extends? P T) => true (satisfies? P (

Re: Protocols and Types

2010-03-03 Thread Konrad Hinsen
On 03.03.2010, at 14:43, Andrea Tortorella wrote: > (extends? P T) > ;==> nil > (satisfies? P T) > ;==> nil > (extenders P) > ;==>nil The doc string of both extends? and extenders refers to types "explicitly extending" a protocol. My understanding is that this excludes protocols implemented via

Re: Protocols and Types

2010-03-03 Thread Shawn Hoover
On Wed, Mar 3, 2010 at 8:43 AM, Andrea Tortorella wrote: > Hi everyone, > > if I run this code: > > (defprotocol P > (foo [x])) > > (deftype T [] > P > (foo [] "dummy")) > > (extends? P T) > ;==> nil > (satisfies? P T) > ;==> nil > (extenders P) > ;==>nil > > are they not yet implemented? > Ni

Protocols and Types

2010-03-03 Thread Andrea Tortorella
Hi everyone, if I run this code: (defprotocol P (foo [x])) (deftype T [] P (foo [] "dummy")) (extends? P T) ;==> nil (satisfies? P T) ;==> nil (extenders P) ;==>nil are they not yet implemented? anyway when I run (type P) ;==> clojure.lang.PersistentArrayMap So the protocol is simply

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread samppi
I see; then that of course would be the reason. Thanks for the answer. On Nov 23, 12:24 pm, Rich Hickey wrote: > On Nov 23, 11:36 am, samppi wrote: > > > > > > > Variable-length arguments in protocols seem to be supported, but > > there's just a weird, stateful behavior. Look what happens when y

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread Rich Hickey
On Nov 23, 11:36 am, samppi wrote: > Variable-length arguments in protocols seem to be supported, but > there's just a weird, stateful behavior. Look what happens when you > call foo first with one argument twice (it fails both times), then two > arguments (it succeeds), then one argument again

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread samppi
Variable-length arguments in protocols seem to be supported, but there's just a weird, stateful behavior. Look what happens when you call foo first with one argument twice (it fails both times), then two arguments (it succeeds), then one argument again (it succeeds now too!). Is this a Clojure bug?

Re: Mysterious errors w/ protocols and types

2009-11-23 Thread Krukow
On Nov 23, 7:36 am, samppi wrote: > The following code contains an error, and I cannot figure out what it > is at all. When I run StateMeta's test once, the statement marked with > a comment above fails. When I run it again, it succeeds. This has been > causing very weird bugs in my code. I've r

Mysterious errors w/ protocols and types

2009-11-22 Thread samppi
The following code contains an error, and I cannot figure out what it is at all. When I run StateMeta's test once, the statement marked with a comment above fails. When I run it again, it succeeds. This has been causing very weird bugs in my code. I've replicated the behavior in both a script and t