From: Anders Borch Date: 2003-07-17T18:54:44+09:00 Subject: Re: Keyword "with" Michael Campbell wrote: >>The fundamental reason, I think, >>is that a Fixnum object (upon which such an operator would operate) >>should never be mutable. > > > Yes. > > >>The x+=1 operator emphasizes that a new Fixnum >>object is being assigned to the applicable variable. > > > No. (To me, anyway). > > I can't say I associate "new object being created" with "+=". Now I know, > deep down, that it's syntactic equivalence to "= .. + ..", and THAT > emphasizes "new object", but on a more gutteral level, "+=" means "new > object creation" no more than "++" would. > > Maybe that's me though. > > I couldn't help myself any longer, I *had* to implement the ++ operator Sadly, we have to load the file with ++ calls explicitly, since a file is parsed before anything is executed, so the appearance of ++ would generate parse errors before we could catch them and replace them with '+=1'. So, I wrote a new load method: def loadpp(l) s = '' prevb = nil f = File.new(l,'r') f.each_byte do |b| if (b == 43 && b == prevb) # 43 is ascii '+' s += '+= 1 ' b = nil # throw away the '++' else s += prevb.chr unless prevb.nil? end prevb = b end s += prevb.chr unless prevb.nil? eval(s) end Now, any file loaded with loadpp may contain the ++ operator, and it will be replaced with '+= 1'. Have fun with it if you like :) /Anders