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

Re: dynamic :use

2009-09-08 Thread Laurent PETIT
Hello, So far there have been mentions of several techniques : => using macro against *db-adapter* : * will work if *db-adapter* is set at compile-time (in a top level expression before the macro call, or as a side effect of the invocation of another macro before the macro call). * if you AOT-c

Re: dynamic :use

2009-09-08 Thread Chris Kent
James Sofra gmail.com> writes: > > > I know that this has come up before on the group and but is this not > essentially dependency injection where the dependency being injected > is a name space that presumably follows a particular convention in > terms of what functions it provides? > > I re

Re: dynamic :use

2009-09-07 Thread James Sofra
I know that this has come up before on the group and but is this not essentially dependency injection where the dependency being injected is a name space that presumably follows a particular convention in terms of what functions it provides? I remember people making it pretty clear that they didn

Re: dynamic :use

2009-09-07 Thread John Harrop
Or, you can go the opposite way and write a macro that expands into the appropriate ns form. This will work if the information you need from *db-adapter* is there by macroexpansion time. A macro that does a similar job to ns, but adds conditional features to the ns "DSL", can wrap and generalize w

Re: dynamic :use

2009-09-07 Thread Chouser
On Mon, Sep 7, 2009 at 1:17 AM, Cliff Wells wrote: > > What I've tried (no laughing!) is this bit of code: > > (ns site.database >  (:use [compojure]) >  (:use [clojure.contrib.sql]) >  (:use [site.setup]) > >  (if (= *db-adapter* "mysql") >    (:use [site.adapters.mysql :as adapter])) >  (if (= *

dynamic :use

2009-09-07 Thread Cliff Wells
Hi, I'm new to Clojure (and Lisp-type languages in general) and I've never used Java... in short, I have a steep learning curve littered with rocks and nails. I also don't know whether it's a good thing that I have long experience with Python and C :-P In any case, as a first project, I'm tryi