Re: matching with wild-cards in clojure multi-methods

2010-09-10 Thread Meikel Brandmeyer
Hi, On 9 Sep., 21:47, Daniel Werner wrote: > Could this be a bug? No. Clojure does not enforce contracts in several places. Feed wrong things in and get undefined behaviour back. Only the contract is guaranteed. Everything else is an implementation detail and might change at any moment. Sincer

Re: matching with wild-cards in clojure multi-methods

2010-09-09 Thread Daniel Werner
On 9 September 2010 07:31, Meikel Brandmeyer wrote: > derive works with non-qualified keywords, but the contract disallows > that: Apparently the contract given in the docstring is being enforced in derive's 2-arg definition, but the "must be namespaced" parts of the assertions are missing from t

Re: matching with wild-cards in clojure multi-methods

2010-09-08 Thread Meikel Brandmeyer
Hi, On 8 Sep., 21:49, Daniel Werner wrote: > Building your own hierarchy would make it safe to use unqualified > keywords as well -- if I am not mistaken? > > (-> (make-hierarchy) > (derive :hello :anything) > ...) derive works with non-qualified keywords, but the contract disallows that:

Re: matching with wild-cards in clojure multi-methods

2010-09-08 Thread Daniel Werner
On Sep 6, 4:43 pm, Meikel Brandmeyer wrote: > You can use qualified keywords with an hierarchy. > > (def your-hierarchy >   (-> (make-hierarchy) >     (derive ::hello ::anything) >     (derive ::world ::anything) >     (derive ::city ::anything) >     (derive ::us ::anything))) Building your own

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Sunil S Nandihalli
thanks Meikel for the suggestion .. I never thought of that .. (or actually didn't know about it).. I think that helps.. Sunil. On Mon, Sep 6, 2010 at 8:19 PM, Meikel Brandmeyer wrote: > Hi, > > On 6 Sep., 16:43, Meikel Brandmeyer wrote: > > > (defmulti foo > > your-dispatch-fn-here > > :hi

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Meikel Brandmeyer
Hi, On 6 Sep., 16:43, Meikel Brandmeyer wrote: > (defmulti foo >   your-dispatch-fn-here >   :hierarchy your-hierarchy) Woops. You should use an atom for the hierarchy or use the Var in the call above: #'your-hierarchy. An atom would allow later modification of the hierarchy. Sincerely Meikel

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Meikel Brandmeyer
Hi, On 6 Sep., 06:14, Sunil S Nandihalli wrote: > (defmethod foo [_          :hello    _         _   ] (str "I'm method 1")) > (defmethod foo [:world   _         :us       _  ] (str "I'm method 2")) > (defmethod foo [:city       _         :us      _  ] (str "I'm method 3")) You can use qualifie

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Sunil S Nandihalli
Thanks Mark for you reply. Well I realized we can do that .. but I feel it would be more expressive and readable if I could do the wild-card like pattern matching when I am defining the method. Sunil. On Mon, Sep 6, 2010 at 9:25 AM, Mark Rathwell wrote: > > You can add essentially one more level

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Sunil S Nandihalli
Hi Mark, Let us say my dispatch function always returns a vector of 4 keywords. now I want to write my methods in the following way.. (defmethod foo [_ :hello_ _ ] (str "I'm method 1")) (defmethod foo [:world _ :us _ ] (str "I'm method 2")) (defmethod foo [

Re: matching with wild-cards in clojure multi-methods

2010-09-06 Thread Sunil S Nandihalli
It looks like the matchure does this kind of thing .. :) .. I guess somebody has already written a library to do what I wanted ... On Mon, Sep 6, 2010 at 9:44 AM, Sunil S Nandihalli < sunil.nandiha...@gmail.com> wrote: > Hi Mark, > Let us say my dispatc

Re: matching with wild-cards in clojure multi-methods

2010-09-05 Thread Mark Rathwell
You can add essentially one more level of indirection to your dispatch function logic and return an integer (or string or whatever) and match on that. So, with your example, when you want "method1" called, return 1 from the dispatch function, when you want "method2" return 2, you get the idea: (d

matching with wild-cards in clojure multi-methods

2010-09-05 Thread Sunil S Nandihalli
Hello everybody, It is awesome that we can specify our own dispatch functions and corresponding values.. However, I feel we should also have control over the functions that is used to match the value of the dispatch function with that of the one specified in the defmethod. For instance if my dis