From: Robert Dober Date: 2008-07-09T17:55:10+09:00 Subject: Re: type specific operator On Wed, Jul 9, 2008 at 10:24 AM, Amitraj singh Chouhan wrote: > Thanks for making me correct. But as in case of x + y it gets converted > to x.+(y). So here the type of x must be known(that is what I mean by > checking type of x) and also to execute + method of x's class and to > pass it argument y, type of y must be known(that is what I mean by > checking the type of y). You can call x.class but believe me that will not give you an exact idea where the message :+ will be intercepted. > These checkings will be done at run time. I would not call it checkings, I would call it method dispatch. AFAIK the message will be dispatched up the ancestor chain until an implementing method is found, if none is found the same search is repeated for #method_missing, however.... >My question is if we have an > Idea about the type of x and y initially(at the time of writing the > program) can we eliminate these type checks. I mean is there any > operator or method call that will directly treat x and y as fixnum. i.e. > something like > int+(x,y) //specific function for adding two > integer > string+(x,y) //specific function for appending > two strings > or any thing like that which will directly trea I believe that people are working on such optimizations via dynamic code analysis but really I am not good enough to give any detailed information about this :(. Maybe you should have a closer look into jruby. HTH Robert -- http://ruby-smalltalk.blogspot.com/ --- AALST (n.) One who changes his name to be further to the front D.Adams; The Meaning of LIFF