Re: Dynamic use of protocols

2010-05-18 Thread Mikhail Kryshen
I don't see how creating MultiFn directly is any less safe than using defmulti which also creates mutable object. And multimethods are never pure functions (may return different values for the same argument after defmethod call). I think the documentation should explicitly state mutability and non-

Re: Dynamic use of protocols

2010-05-17 Thread Sean Devlin
You could create a local instance of clojure.lang.MultiFn in a let binding, and access it directly. You can see the definition of the object here: http://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/MultiFn.java The very good reason you DO NOT DO THIS is that this object is MUT

Re: Dynamic use of protocols

2010-05-17 Thread Laurent PETIT
2010/5/17 Mikhail Kryshen : > On 17 май, 12:07, Laurent PETIT wrote: >> Yes, >> >> as David wrote, >> >> What you're describing is not single-dispatch-based polymorphism (e.g. >> like in java), it's double dispatch (because you want to dispatch to >> the implementation of the protocol function bas

Re: Dynamic use of protocols

2010-05-17 Thread Mikhail Kryshen
On 17 май, 12:07, Laurent PETIT wrote: > Yes, > > as David wrote, > > What you're describing is not single-dispatch-based polymorphism (e.g. > like in java), it's double dispatch (because you want to dispatch to > the implementation of the protocol function based on both the type and > another par

Re: Dynamic use of protocols

2010-05-17 Thread Laurent PETIT
Yes, as David wrote, What you're describing is not single-dispatch-based polymorphism (e.g. like in java), it's double dispatch (because you want to dispatch to the implementation of the protocol function based on both the type and another parameter which may be totally dynamic, or materialized -

Re: Dynamic use of protocols

2010-05-16 Thread David Nolen
On Saturday, May 15, 2010, Mikhail Kryshen > set of extenders and implementing functions. This state (what > types currently implement the protocol and how) is what I really > want to be able to manipulate. The way it is tied to the protocol > definition and changed by the extend function seems to

Re: Dynamic use of protocols

2010-05-16 Thread Mikhail Kryshen
On 16 май, 05:57, ataggart wrote: > Perhaps you misunderstand protocols.  Protocols don't support a > hierarchy, thus you don't extend them; you have types implement/reify > them.  Any "extending" you do will be against a type. By extending the protocol I mean "extending the polymorphism of the p

Re: Dynamic use of protocols

2010-05-16 Thread Mikhail Kryshen
On 16 май, 05:57, ataggart wrote: > Perhaps you misunderstand protocols.  Protocols don't support a > hierarchy, thus you don't extend them; you have types implement/reify > them.  Any "extending" you do will be against a type. By extending the protocol I mean "extending the polymorphism of the p

Re: Dynamic use of protocols

2010-05-15 Thread ataggart
dds state > (current set of extenders and corresponding implementations) and > extend function does not modify the protocol structure itself nor does > it return new version of it but changes the state elsewhere. This > makes dynamic use of protocols (e.g. having functions that crea

Dynamic use of protocols

2010-05-15 Thread Mikhail Kryshen
es it return new version of it but changes the state elsewhere. This makes dynamic use of protocols (e.g. having functions that create, accept or return protocols) problematic. Also it may be useful to have with-protocol macro that will bind function vars to the implementations associated wit