Re: Defaults for multi-argument dispatch

2009-03-20 Thread Konrad Hinsen
On Mar 20, 2009, at 16:18, Rich Hickey wrote: >> Providing a :default implementation for multimethods is a very common >> and useful technique, but it is really useful only for multimethods >> that dispatch on a single argument. > > I disagree about that. No dispatch value, composite or not, is s

Re: Defaults for multi-argument dispatch

2009-03-20 Thread Konrad Hinsen
On Mar 20, 2009, at 16:35, Paul Stadig wrote: > You could use multiple multi-methods: ... Not pretty, as you said, but also not quite the same in behaviour as a single multimethod dispatching on both arguments. Multiple dispatch can be made symmetric in the arguments, whereas a chain of m

Re: Defaults for multi-argument dispatch

2009-03-20 Thread Paul Stadig
It's also not as maintainable as using a single multi-method. Like I said, not pretty, but it works. Paul On Fri, Mar 20, 2009 at 11:38 AM, David Nolen wrote: > This works well as long as you don't mind the perf hit for the second > dispatch :) > > > On Fri, Mar 20, 2009 at 11:35 AM, Paul Stad

Re: Defaults for multi-argument dispatch

2009-03-20 Thread David Nolen
This works well as long as you don't mind the perf hit for the second dispatch :) On Fri, Mar 20, 2009 at 11:35 AM, Paul Stadig wrote: > You could use multiple multi-methods: > > user=> (defmulti plus-int (fn [x y] (type y))) > #'user/plus-int > user=> (defmethod plus-int :default [x y] (println

Re: Defaults for multi-argument dispatch

2009-03-20 Thread Paul Stadig
You could use multiple multi-methods: user=> (defmulti plus-int (fn [x y] (type y))) #'user/plus-int user=> (defmethod plus-int :default [x y] (println "the first is an int")) # user=> (defmethod plus-int java.lang.Double [x y] (println "one of each")) # user=> (defmulti plus (fn [x y] (type x)))

Re: Defaults for multi-argument dispatch

2009-03-20 Thread Rich Hickey
On Mar 20, 10:56 am, Konrad Hinsen wrote: > Providing a :default implementation for multimethods is a very common > and useful technique, but it is really useful only for multimethods > that dispatch on a single argument. I disagree about that. No dispatch value, composite or not, is still a v

Defaults for multi-argument dispatch

2009-03-20 Thread Konrad Hinsen
Providing a :default implementation for multimethods is a very common and useful technique, but it is really useful only for multimethods that dispatch on a single argument. What I am looking for is an equivalent technique for multiple-argument dispatch. Suppose you have a multimethod + of