On 2010/09/08 23:44, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: [ruby-core:32143] Re: Ruby 2.0 Wiki/Wish-list?"
>      on Wed, 8 Sep 2010 23:21:59 +0900, Roger Pack<rogerdpack2 / gmail.com>  writes:
>
> |++x and x++
> |I realize it's "implicit" and "mysterious" shorthand, but we already
> |have shorthand in x += 1, so why not?)
>
> I have already rejected this idea many times.

I agree. C and similar languages need ++i and i++ a lot for loops. Ruby 
has each and friends (and each_with_index if the index is really needed).

What might make sense is a better error message. People (some of my 
students included) coming from C-like languages and learning Ruby would 
be helped a lot by an error message like "++ operator not available in 
Ruby" or so.

> But just for curiosity, how do you define the semantics of x++ and
> ++x, where you don't have explicit type for variables in Ruby.
> For x += 1, it's easily defined as x = x + 1, but not that easy for
> x++ and ++x.

I don't understand how this relates to explicit types for variables. ++x 
is just x = x + 1. x++ is something like (x'=x, x = x+1, x'). Ruby 
doesn't have the C comma operator, and this can't implemented as a 
method, because we can't pass a variable by reference (the equivalent of 
&x in C) in Ruby. But this isn't relevant because like += and friends, 
++ would just be syntactic sugar implemented by the interpreter, not 
overridable operators.

Regards,   Martin.

-- 
#-# Martin J. D?rst, Professor, Aoyama Gakuin University
#-# http://www.sw.it.aoyama.ac.jp   mailto:duerst / it.aoyama.ac.jp