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

Except 1++ wouldn't work, any more than 1 += 1 would work.

Again, the suggestion was that it work the same way += does -- and += doesn't
rely on a .succ! method of any kind. It would be purely syntactic sugar, the
way +=.

In other words, it would still parse to:

foo = foo + 1

Or, maybe slightly better, it would parse to:

foo = foo.succ

it would just be shorter to write than

foo += 1

The immutability of integers is a good thing for people to know, yes.
It's also completely irrelevant to this discussion.

And for the record, I'm playing devil's advocate -- the real issue seems to be
that ++ would add to the parsing complexity of it. I'm guessing most of us
rarely do +=1, so most of us wouldn't really use it, so it's not worth that
complexity.

But it's by no means impossible, or a fundamental change to the language.
All it does is make the parser more complex.

···

On Saturday 30 August 2008 13:11:38 Erik Hollensbe wrote:

David Masover wrote:
> Why not add a ++ that works the same way += does?

1++ would have to operate (essentially) like 1.succ!

Do you mean, people should not write
a = a + 1
because of GC issues???
Robert

···

On Thu, Aug 28, 2008 at 11:56 PM, John Pritchard-williams <monojohnny@googlemail.com> wrote:

... and as Integers are immutable ++ cannot change the underlying object..

That makes sense : and I guess 'x++'=> x+1 would be just confusing..

I mean like this:

a+=1 (which of course IS valid)

a++ - could in theory mean "Take the value pointed at by a currently,
increment it and re-point 'a' at that new object"...

but then people might abuse it and not realize (as I hadn't really) that
Integers are immutable...and give the garbage collector a really hard
time...

--
C'est véritablement utile puisque c'est joli.

Antoine de Saint Exupéry

Roger Pack wrote:

David Masover wrote:

... Then again, why pollute our namespace with an operator that would see
so
little use? I can't remember the last time I had to use "+=1" in Ruby.

I wish we had it. But that's just me.

Ruby doesn't use ++ because that would .succ!

No it would not, and if you have good memories you know who was the
fool who proposed succ! once, LOL.
The worst is that this confusion is totally my fault because I was
talking about Integer's immutability completely out of context.
Sorry.
R.

···

On Fri, Aug 29, 2008 at 3:25 PM, Phlip <phlip2005@gmail.com> wrote:

--
http://ruby-smalltalk.blogspot.com/

There's no one thing that's true. It's all true.
--
Ernest Hemingway

David Masover wrote:

···

On Saturday 30 August 2008 13:11:38 Erik Hollensbe wrote:

David Masover wrote:
> Why not add a ++ that works the same way += does?

1++ would have to operate (essentially) like 1.succ!

Except 1++ wouldn't work, any more than 1 += 1 would work.

But it's by no means impossible, or a fundamental change to the
language.
All it does is make the parser more complex.

You're right, and boy is that an embarassing omission on my part. :slight_smile:

-Erik
--
Posted via http://www.ruby-forum.com/\.