On Wed, 27 Jun 2001, Yukihiro Matsumoto wrote: > I admint explicit dispatch based on type often comes first to mind. > But I think things go better if we design programs based on protocols > (i.e. based on set of methods that objects can respond). As I may have said before, you can make protocols correspond to empty modules, and consider inclusion of such a module Foo as a declaration of intent: "this class is supposed to be supporting the Foo protocol". In addition, I use the notation FooP to say "the Foo protocol (by opposition to: the Foo implementation)", in cases where you begin by a class ("Array") and you extract a protocol from it ("ArrayP") so that you can check for Array-emulator classes easily. (this is in MetaRuby 0.7) On Wed, 27 Jun 2001, Yukihiro Matsumoto wrote: > |So if it (i.e. Guy's implementation) doesn't make too much overhead (if > at all) and too much integration problems I would suggest to open up a > RCR, so that everybody could give his opinion. > It's OK for me to open up new RCR. But to tell the truth, I feel like > that explicit dipatch based on type is not a Ruby-way(TM). You don't > have to give it up though. Allowing several concurrently existing defs for the same name causes a problem, as a single method of class can no longer always be referred to by a single symbol. So, I propose that the proposal be changed such that it is a single method definition, but with multiple bodies. This could be like: class Array def [] (Integer i) # fetch single element ordef (Integer i, Integer n) # fetch sequence by length ordef (Range r) # fetch sequence by range end end but introducing two new big features, type checking and multipart methods, with both an impact on the syntax and interpreter, may be too much at once. maybe we can start with something like this: class TypeList class<<self; alias [] new; end def initialize(*list) @list = list end def ===(args) return false if not @list.length == args.length @list.length.times {|i| return false if not @list[i] === args[i] } return true end end class Blahray def [] (*args); case args when TypeList[Integer]; i,=args # fetch single element when TypeList[Integer,Integer]; i,n=args # fetch sequence by length when TypeList[Range]; r=args # fetch sequence by range else raise TypeError, "it's your fault" end end end or maybe people would prefer: class Array def matching(*types) return false if not length == types.length length.times {|i| return false if not types[i] === self[i] } yield end end class Blahray def [] (*args) args.matching(Integer) {|i,| # fetch single element here return value } args.matching(Integer,Integer) {|i,n| # fetch sequence by length here return values } args.matching(Range) {|r| # fetch sequence by range here return values else raise TypeError, "it's your fault" end end So, how ugly are those solutions? ;-) (yes, i didn't really try them!) matju