Re: A value that equals everything, or, ignoring things in multi-dispatch
what i think would be nice here is multimethods taking multiple dispatch functions. (i'm not sure how you'd do that without breaking the default value syntax) so it'd try the first function, and if it doesn't match any method, then it tries the second, etc. then :default, then throws an exception. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: A value that equals everything, or, ignoring things in multi-dispatch
All multimethods have :default as the default fallback value, regardless of what the dispatch function is. But I assume that only works with single values. Maybe what you want is TWO multimethods, one that dispatches on the first value, then calls the second multimethod to dispatch on the other value. -S On Nov 15, 2:36 pm, 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? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: A value that equals everything, or, ignoring things in multi-dispatch
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) # user=> (defmethod a 5 [x y] :five) # 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 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 -~--~~~~--~~--~--~---
A value that equals everything, or, ignoring things in multi-dispatch
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? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---