From: Chris Moline Date: 2001-08-24T14:26:06+09:00 Subject: [ruby-talk:20248] Re: ++ Operator On Fri, Aug 24, 2001 at 04:46:32AM +0900, Guillaume Cottenceau wrote: > Maybe I just don't see the future problems, but I think it would not be > very confusing. It would try to "increment" the object behind the > variable. It would fail just as it currently fails, on a String: > > irb(main):001:0> a = "foo" > "foo" > irb(main):002:0> a += 1 > TypeError: failed to convert Fixnum into String > from (irb):2:in `+' > from (irb):2 > irb(main):003:0> > > > The ++ would also fail.... unless you would imagine it should succeed for > some reason ? If the "++" is just converted to "+= 1" ok it would fail for > the same reason, but I imagine you would like that the "++" behaves > differently among objects because some of them could be "incremented" > while not "added the Fixnum `1'". > > In my opinion, I would not be shocked if it would simply convert to +=1 > and then fail for relevant reason for most objects. > > The only moment where I miss the "++" is actually when I need to increment > a Number... Writing "a += 1" is just.. depressing.. ;p. I agree with you here. I would like to see "++" as an opertor that can be redefined as appropriate as much as "+" or "<<". Then for strings it might be string.succ and for fixnums it would be += 1 and an error for where it's inappropriate. But i don't know how much trouble that would be to implement. Have you tried making it a behaviour?? I haven't yet but I will soon Sincerly, Chris Moline