I'm just wondering—is there a way to match methods' dispatch-values
using a function other than isa?—such as with a macro. This is what
I'm thinking of:

  (defmulti foo identity #(re-find %2 %1)) ; uses the last function
instead of isa? to match

  (defmethod foo #"xyzzy" [x]
    x))

  (defmethod foo #"plugh" [x]
    (str x "!"))

  (defmulti bar identity #(%1 %2)) ; uses the last function to match

  (defmethod #(apply distinct? %) [x]
    x))

  (defmethod (fn [x] (some #(> % 3) x)) [x]
    (conj x 1 3))

  (foo "arstninixyzzy") ; matches the first method, returns
"arstninixyzzy"
  (foo "arstplughars") ; matches the second method, returns
"arstplughars!"
  (foo "arststr") ; does not match anything, raises error

  (bar [3 2 5]) ; matches the first method, returns [3 2 5]
  (bar [2 3 5 3]) ; matches the second method, returns [2 3 5 3 1 3]
  (bar [1 2 0 2]) ; matches nothing, raises error

This may not an important enough feature to support in the core; I'm
just thinking it may come useful in the future, and so am wondering if
it's possible with a macro.


--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to