Hi -- Jean-Hugues ROBERT <jean_hugues_robert / yahoo.com> writes: > At 08:19 22/04/2004 +0900, you wrote: > > >The problem with abs! is that you can't modify a number in place, > >because numbers are immediate values (even when referenced by > >variables), and there's only one copy of each in existence. So if you > >did this: > > > > -1.abs! > > > >then henceforth 1 + -1 would be 2, because you would have changed -1 > >*itself* to 1 (not just assigned 1 to a variable that previously > >referenced -1). The same would be true of this: > > > > x = -1 > > x.abs! # x is the immediate value -1 > > > >This is also why there are no ++ and -- operators in Ruby. 1++ would > >mean that the actual number 1 would henceforth mean 2. > >David > > 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). 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 -- David A. Black dblack / wobblini.net