From: Dan Sugalski Date: 2002-09-12T21:14:46+09:00 Subject: Re: Multimethods (was Re: Larry Wall's comments on Ruby) At 6:59 PM +0900 9/12/02, Friedrich Dominicus wrote: >Dan Sugalski writes: > >> At 12:57 AM +0900 9/12/02, Christoph wrote: >> >"Dan Sugalski" wrote in >> >.... >> >> That's pretty much multimethods. They're terribly useful, as they cut >> >> out a lot of checks for the second type in methods. (Checks which >> >> tend to be slow, error prone, and missing stuff) >> > >> >Thanks Dan, for making such an eloquent case for multimethods. >> >Personal I cannot image (surely an effect of being single and >> >simple minded;-) how their use could be less complex then the >> >alternatives like Rubys coerce framework or double-dispatch .. >> >> Their big problem is that they introduce methods that don't live in >> any class. If you have the methods: >> >> >> add(int, num) >> add(num, int) >> add(bignum, int) >> >> those three, while methods, don't live in any class, so if you did: >> >> foo.add(bar) >sorry any from the above has nothing to do with this one. >you could have >a foo.add(int,num) > foo.add(num,int) >.. >and yo can have a foo.add(bar). Sorry, I wasn't being clear--foo would have been an int, a num, or a bigint. The first parameter's generally taken to be the type of the object the method ultimately gets invoked in. Since the various incarnations of a multimethod live outside any class, you can't count on the type of the class as implicit in the signature. Also, since multimethods live outside any class, you can have a class that provides a version of a method where the left hand argument is not the class where the method happens to be defined. For example, if you had a method like: blah(int, some_blah_thing); blah(string, some_blah_thing); blah(file, some_blah_thing); they'd be defined (probably) in the some_blah_thing class, since that's the class that has knowledge of them, but they'd still work if you did: 1.blah(some_blah_object) (You'll pardon the syntax--take it as pseudocode, as I don't really do syntax) -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk