On Nov 16, 12:36 am, samppi <[EMAIL PROTECTED]> wrote:
> Is there a way to get a value—call it 'anything—so that (isa? anything
> x) is always true for any x?
>
> I need this for multimethod dispatch—sometimes, I want a method to
> ignore some of the stuff its dispatch function returns:
>
>   (defmulti a #(%1 %2))
>
>   (defmethod a [3 2] [x y] ...)
>
>   ; in this method, the second dispatch value is ignored and
>   ; the method matches any call whose first argument is 5
>
>   (defmethod a [5 anything] [x y] ...)
>
> I wish the _ symbol would do this, but it doesn't work (if practical,
> it'd be cool if it were implemented in the future :). Is there some
> sort of solution possible right now?

There could be some problem constraints I don't understand
here but maybe you could just use "first" (or some custom
function) to extract the relevant args

user=> (defmulti a #(first [%1 %2]))
#'user/a
user=> (defmethod a 3 [x y] :three)
#<MultiFn [EMAIL PROTECTED]>
user=> (defmethod a 5 [x y] :five)
#<MultiFn [EMAIL PROTECTED]>
user=> (a 3 4)
:three
user=> (a 3 5)
:three
user=> (a 5 5)
:five

Parth


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
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