From: Dan Sugalski Date: 2002-09-12T15:45:34+09:00 Subject: Re: Multimethods (was Re: Larry Wall's comments on Ruby) At 1:26 AM +0900 9/12/02, Hal E. Fulton wrote: >----- Original Message ----- >From: "Dan Sugalski" >To: "ruby-talk ML" >Sent: Wednesday, September 11, 2002 9:56 AM >Subject: Multimethods (was Re: Larry Wall's comments on Ruby) > > >> At 10:48 PM +0900 9/11/02, Gavin Sinclair wrote: >> >Despite the discussion and links, I haven't picked up on what >multimethods >> >actually are, so I can't comment on those. > >(snip informative stuff} > >> 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) > >That's it? I thought it would be more esoteric and >interesting. Yup, that's it. Kinda like continuations. They seem all mysterious and bizarre until you figure it out. (Though in the case of continuatuions they stay bizarre, just not mysterious :) >Do people really consider that a "multiple-receiver" >In any case, I wouldn't favor adding this to Ruby, >as variables have no types; and thus how do you >define a method "signature"? MM dispatch is a runtime thing, and at runtime you *can* determine the types of the variables being used in the method. While the variable may, in general, hold anything, when the call is made we can definitely figure out what type it has now. (Or, if you rather, you can think of MM dispatch dispatching on the type of the value type rather than the variable type) >What's more, a method with a single parameter can >be passed an object of ANY type. I'd hate to define >a method for each type I expected (as I would in >C++ or Java), especially since that would preclude >types I *didn't* expect. You don't have to. This dispatch mechanism respects the hierarchy, and generally there's a mechanism to mark a default method that gets called if nothing matches. -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk