Why no ++ and --?

I don't think so, no more than it points to a shortcoming of Ruby that
you can't implement = as an operator.

-s

···

On 2010-02-16, lith <minilith@gmail.com> wrote:

I find that issue interesting in a slightly different perspective.
Shouldn't it be possible to implement that operator right in ruby and
doesn't it point to a shortcoming that there is no way to implement it
(other than using a decorator).

--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

++ and -- modify their receivers. Since Ruby's Numeric types are immutable,
they cannot be modified. So the only solution is to implement ++ and -- as
assignment operators.

Other languages solve similar problems by providing references/
pointers to variable or with macros etc. This isn't about
immutability.

++ and -- modify their receivers. Since Ruby's Numeric types are immutable,
they cannot be modified. So the only solution is to implement ++ and -- as
assignment operators.

Other languages solve similar problems by providing references/
pointers to variable or with macros etc.

I don't think allowing references or pointers to variables would be good.
Variables are not objects, they're references already.

This isn't about immutability.

In practice it is, because when people say "x++", they don't want the variable
x to refer to a new object, they want the object x refers to increased.

-s

···

On 2010-02-16, lith <minilith@gmail.com> wrote:
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

Don't agree with that. For me the contract is just about the variable.
People do not want to be able to do ++5, you can't do that in
languages that offer ++ either.

···

On Tue, Feb 16, 2010 at 6:50 PM, Seebs <usenet-nospam@seebs.net> wrote:

In practice it is, because when people say "x++", they don't want the variable
x to refer to a new object, they want the object x refers to increased.

In C:

++*p;

Has nothing to do with the variable, has everything to do with the object
denoted by the expression '*p'.

In C, the variable denotes a region of storage. In Ruby, it doesn't.

-s

···

On 2010-02-16, Xavier Noria <fxn@hashref.com> wrote:

On Tue, Feb 16, 2010 at 6:50 PM, Seebs <usenet-nospam@seebs.net> wrote:

In practice it is, because when people say "x++", they don't want the variable
x to refer to a new object, they want the object x refers to increased.

Don't agree with that. For me the contract is just about the variable.
People do not want to be able to do ++5, you can't do that in
languages that offer ++ either.

--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
| Seebs.Net <-- lawsuits, religion, and funny pictures
Fair game (Scientology) - Wikipedia <-- get educated!

You could argue that for += as well:

    *p += 1;

Does that C use case rule out += in Ruby? Nope we have our own +=
right? Same a posteriori for ++ in my opinion. It could be implemented
given the expectations that are reasonable to have in Ruby.

···

On Tue, Feb 16, 2010 at 7:30 PM, Seebs <usenet-nospam@seebs.net> wrote:

On 2010-02-16, Xavier Noria <fxn@hashref.com> wrote:

On Tue, Feb 16, 2010 at 6:50 PM, Seebs <usenet-nospam@seebs.net> wrote:

In practice it is, because when people say "x++", they don't want the variable
x to refer to a new object, they want the object x refers to increased.

Don't agree with that. For me the contract is just about the variable.
People do not want to be able to do ++5, you can't do that in
languages that offer ++ either.

In C:

++*p;

Has nothing to do with the variable, has everything to do with the object
denoted by the expression '*p'.

In C, the variable denotes a region of storage. In Ruby, it doesn't.

And += can result in a sequence of message exchanges as well:

obj.meth += 1
obj[member] += 1

These will need to invoke the respective getters and setters for obj, in
addition to invoking '+' on the object returned from the getter.

In that regard += is very much sugar for:

obj.meth = obj.meth + 1

···

On Tue, Feb 16, 2010 at 11:52 AM, Xavier Noria <fxn@hashref.com> wrote:

You could argue that for += as well:

   *p += 1;

Does that C use case rule out += in Ruby? Nope we have our own +=
right? Same a posteriori for ++ in my opinion. It could be implemented
given the expectations that are reasonable to have in Ruby.

--
Tony Arcieri
Medioh! A Kudelski Brand