Re: Please don't flame me...why is there no "++" in Ruby again ?



On Fri, Aug 29, 2008 at 12:04 AM, Robert Dober <robert.dober@xxxxxxxxx> wrote:
On Fri, Aug 29, 2008 at 7:27 AM, David Masover <ninja@xxxxxxxxxxxx> wrote:
On Thursday 28 August 2008 16:25:59 Joel VanderWerf wrote:
John Pritchard-williams wrote:
I did check my Ruby books by the way, but they just "unlike C there is
no ++ operator in Ruby...." :)

In ruby, operators are methods and they operate on objects, not on
variables.

That's not really a valid reason, and not entirely true -- there is no +=
method for you to define. It behaves as though it's a macro:
You are right of course, the original question was, why is there no
x++ as syntactic sugar for x = x + 1.

Because Ruby is hard enough to parse as it is. After all, ++x is
already valid Ruby. equivalent to x.send(:"+@").send(:"+@"). And x++x
is valid (though odd) Ruby, equivalent to x.+(x.send(:"+@")).

Its probably better to just let people use x+=1.

.



Relevant Pages

  • Re: Need - macros feature
    ... It's good for new in Ruby. ... You wrote the macro once and put it in macro library ... macro: %var ...
    (comp.lang.ruby)
  • [ANN] rubymacros 0.1.5 Released
    ... RubyMacros is a lisp-like macro pre-processor for Ruby. ... in RedParse format, they're easier to use and more object- ...
    (comp.lang.ruby)
  • Re: Need - macros feature
    ... > Matthew Johnson wrote: ... It's good for new in Ruby. ... > You wrote the macro once and put it in macro library ... > macro: %var ...
    (comp.lang.ruby)
  • Re: Macros calling macros
    ... block "outer block" ... The indent level gets set and passed on to the next macro expansion ... But in your Ruby, ...
    (comp.lang.lisp)
  • Re: Need - macros feature
    ... It's good for new in Ruby. ... What I want is a classic Macroprocessor tool. ... You wrote the macro once and put it in macro library ... There are plenty of editors with comprehensive macro functions. ...
    (comp.lang.ruby)