From: Justin Johnson Date: 2002-09-25T19:02:37+09:00 Subject: Re: adding overload to ruby IMHO, I think that having dispatch like this would be cool. But... Issues: 1. It would have to be optional. Each parameter could be either a var (as it is now) or a class and var pair to specify specialization. 2. Making it efficient could be difficult. It could potentially affect the speed of all method lookups because a method call would have to get the types of the arguments and try and find a matching method. If it can't find one it would presumably use the totally generic case. Example: def a_method( a, b, c ) #generic case ... end def a_method( String a, Fixnum b, Fixnum c ) #specialized case ... end a_method( "hello", 10, 20 ) #calls specialized case above a_method( 10, "hello", "there" ) #can't find specialized for (Fixnum,String,String) so defaults to generic. 3. Bignum and Fixnum. Conversion between these are automatic. How does this affect specialization? Example: def a_method( Fixnum a ) ... end def a_method( Bignum a ) ... end a_method( 1000 ) #calls Fixnum a_method a_method( 100000000000000000000000000 ) #calls Bignum a_method Is this desirable? Probably not. -- Justin Johnson "Bulat Ziganshin" wrote in message news:67179315231.20020924111057@integ.ru... > Hello all and especially Matz, > > there is permanent discussion about adding overload facility to ruby > and spirit of language. i want to add another cent to this :) > > now i can use overload library and write code such as: > > > def do_overload(i, s, f) > > end > > overload(:do_overload, Fixnum, String, Float) > > > > def do_overload(s, i, *a) > > end > > overload(:do_overload, String, Fixnum) > > all that i want - just the same (terrible, you are right) semantics > with a bit more clear syntax and including this feature into ruby > distribution: > > > def do_overload(Fixnum i, String s, Float f) > > end > > def do_overload(String s, Fixnum i, *a) > > end > > although this don't correspond to dynamic spirit of language, in real > world this adds lot of points to ease of use and even robustness of > language > > -- > Best regards, > Bulat mailto:bulatz@integ.ru > >