From: Justin Johnson Date: 2002-09-25T23:02:55+09:00 Subject: Re: adding overload to ruby > not class, but any expression - we can use === to test Of course. Cool. > def a_method( Integer a) > end > > def b_method( Numeric a) > end Yes, I thought of this. This means however that the lookup needs to work with class hierarchies: a_method( 10 ) # parameter is a Fixnum object Lookup for a_method with a Fixnum find a match. So the call has to navigate the Fixnum hierarchy to try and find a match. This gets slower/harder with multiple arguments. > no. if the method definition don't use type specifiers, this method is > not overloaded. as with overload.rb Ok, but how does the runtime know wether a method call is overloaded at the point of call? It doesn't. It would have to work out the argument classes and perform a lookup based on them. For most method calls it wouldn't find a specialized version and would have to call the generic method instead. -- Justin Johnson "Bulat Ziganshin" wrote in message news:16124073525.20020925163403@integ.ru... > Hello Justin, > > Wednesday, September 25, 2002, 2:02:37 PM, you wrote: > > JJ> 1. It would have to be optional. Each parameter could be either a var (as > JJ> it is now) or a class and var pair to specify specialization. > > not class, but any expression - we can use === to test > > JJ> 2. Making it efficient could be difficult. It could potentially affect the > JJ> speed of all method lookups because a method call would have to get the > JJ> types of the arguments and try and find a matching method. If it can't find > JJ> one it would presumably use the totally generic case. > > no. if the method definition don't use type specifiers, this method is > not overloaded. as with overload.rb > > JJ> 3. Bignum and Fixnum. Conversion between these are automatic. How does > JJ> this affect specialization? > > def a_method( Integer a) > end > > def b_method( Numeric a) > end > > >> 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 > >