yea Ken I agree with you.. but it was just an exercise .. you could
definitely add a priority option to every method.. Thanks for your
comments.. besides the code was tested..
Sunil.

On Thu, Dec 23, 2010 at 11:45 AM, Ken Wesson <kwess...@gmail.com> wrote:

> On Thu, Dec 23, 2010 at 1:09 AM, Ken Wesson <kwess...@gmail.com> wrote:
> > An untested implementation:
>
> Yeah, there's a bug or two.
>
> > (def qlzqqlzuup (Object.))
> >
> > (defmacro my-defmulti [name]
> >  `(def name
>
> Should be ~name.
>
> >     (let [dtable (atom (sorted-map))]
>
> Should be dtable#, and likewise the rest of the local symbols in the
> def. Probably best to hoist the bulk out to a function:
>
> (defn dispatch-multi [dtable arg-seq]
>  (if (= (first arg-seq) qlzqqlzuup)
>    (let [[_ pri predmeth] arg-seq]
>       (swap! dtable assoc pri predmeth))
>      (loop [d (seq @dtable)]
>        (if d
>          (let [[_ [pred meth]] (first d)]
>             (if (apply pred arg-seq)
>              (apply meth arg-seq)
>                 (recur (next d))))
>           (throw IllegalArgumentException
>            (str "no matching method in " name " for " args)))))))
>
> (defmacro my-defmulti [name]
>  `(def ~name
>     (let [dtable# (atom (sorted-map))]
>        (fn [& args#]
>         (dispatch-multi dtable# args#)))))
>
> Warning: still untested.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to