From: Jean-Hugues ROBERT Date: 2004-04-24T02:37:21+09:00 Subject: Re: Creating bang methods About ++ & += operators... At 21:59 23/04/2004 +0900, David wrote: >Jean-Hugues ROBERT writes: > > Well... something++ could get expanded into (something = something.++()) ? > > And ++something get expanded into (tmp = something, something = > > something.++(), tmp) > > Pure syntax sugar. > > Then you can: > > def ++() self + 1 end > > I think += does that already, doesn't it ? > > There are other reasons why there is no ++ in Ruby. > >Well, I'll take your word for it, but apparently Matz is keeping them >secret :-) I'm just summarizing the reasons Matz has talked about in >the past (the illogic of incrementing integers, which are unique and >immutable, and which are present as immediate values in the variables >that represent them). That there would be other reasons does not mean that I know what they are ;-) >Of course the parser could be taught to do what you describe -- it's >just that it wouldn't make sense. Keep in mind that these two things >are equivalent: > 1++ >and > x = 1 > x++ >so if the former makes no sense, then neither does the latter. Making >some sort of special case where, suddenly, integers are not immmediate >values strikes me as not very sugary :-) >David I agree that 1 += 1 does not make much sense, yet x = 1 x += 1 does make some sense. I am not advocating for special cases when I assume that some kind of lvalue exists, or am I ? Jean-Hugues