On Feb 8, 2010, at 2:30 PM, Tony Arcieri wrote: > On Mon, Feb 8, 2010 at 12:20 PM, Seebs <usenet-nospam / seebs.net> > wrote: > >> You can't increment the underlying object, because fixnums are >> immutable. >> > > Not to beat the dead horse any more but... > > In a language like Ruby where the binding operates entirely by > reference, it > would only make sense for the ++ operator to change which object a > variable > name references (i.e. destructive assignment) as opposed to sending a > message which actually mutates the object it references, especially > since ++ > is an operator intended to work with numbers and Ruby's numbers are > immutable. > > Using x++ as a shorthand for: > > begin; _tmp = x; x += 1; _tmp; end > > ...would be the only sensible implementation. > > There exists an operator in Ruby which doesn't send a message: =. > The "=" > operator modifies the binding. ++ (and --) would have to do the same. > > Unprecedented? Yes. But not impossible. > > -- > Tony Arcieri > Medioh! A Kudelski Brand Well, I could see a sensible implementation equivalent to: begin; _tmp = x; x = x.succ; _tmp; end or perhaps begin; _tmp = x; x.succ!; _tmp; end so that's certainly not the "only" sensible implementation :-) -Rob P.S. Sorry from flailing the horse. Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com