[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: RCR again (Integer#succ!, Integer#pred!

Gregory Brown

1/12/2007 6:16:00 PM

On 1/12/07, Robert Dober <robert.dober@gmail.com> wrote:

> x = 41
> x.succ! => 42
> x => 42

This is probably in the same vein as ++.

I don't like it because since integers are immediate values in ruby,
that looks messy.

6 Answers

Daniel Berger

1/12/2007 6:22:00 PM

0


Gregory Brown wrote:
> On 1/12/07, Robert Dober <robert.dober@gmail.com> wrote:
>
> > x = 41
> > x.succ! => 42
> > x => 42
>
> This is probably in the same vein as ++.
>
> I don't like it because since integers are immediate values in ruby,
> that looks messy.

How about....x++ ?

I know, I know - it's pretty radical, but it's 2007. I think we're
ready.

Regards,

Dan

PS - Evan Phoenix did this for Sydney, so it's possible. Evan, got a
parse.y patch for us?

Logan Capaldo

1/12/2007 6:47:00 PM

0

On Sat, Jan 13, 2007 at 03:25:06AM +0900, Daniel Berger wrote:
>
> Gregory Brown wrote:
> > On 1/12/07, Robert Dober <robert.dober@gmail.com> wrote:
> >
> > > x = 41
> > > x.succ! => 42
> > > x => 42
> >
> > This is probably in the same vein as ++.
> >
> > I don't like it because since integers are immediate values in ruby,
> > that looks messy.
>
> How about....x++ ?
>
> I know, I know - it's pretty radical, but it's 2007. I think we're
> ready.
>
Maybe x++. I'm pretty sure it can't be a method.
consider x.method(:succ!), letting x fall out of scope and then
invoking #call on that method. Ruby would have to realize it would need
to make a closure (unless we just had no unboxed values).
> Regards,
>
> Dan
>
> PS - Evan Phoenix did this for Sydney, so it's possible. Evan, got a
> parse.y patch for us?
>

dblack

1/12/2007 7:35:00 PM

0

Daniel Finnie

1/12/2007 8:13:00 PM

0

Daniel Berger wrote:
> How about....x++ ?

x++ in languages that implement it (PHP I'm sure of, Java and C++ I'm
less sure of) increment x after running the statement. So:

# All of the ++s are how it would be in PHP/Java/C++
def printNum x
puts x.to_s
end

x = 42
printNum(x++) #=> 42
printNum(x) #=> 43

x = 42
printNum(x.succ!) #=> 43
printNum(x) #=> 43

++x increments before passing the variable:
printNum(++x) #=> 44
printNum(x) #=> 44

So even if this was implemented, I think x++ would be a bad syntax to
x.succ! as other languages have something which looks exactly the same
and yet does something different.

Dan

Gavin Kistner

1/12/2007 8:20:00 PM

0

dbl...@wobblini.net wrote:
> Even when it's 2007++ integers will still be immutable, immediate
> values :-) I much prefer having people have to learn that that's how
> Ruby integers are.

To be fair, that's a perfectly reasonable argument if ++ were to be a
method call. If it's to be programmer convenience for x += 1 (syntax
sugar for x=x+1) however, it could also be implemented as syntax sugar.

I'm personally perfectly happy without ++, but there are certainly ways
that it *could* be added to Ruby without violating the immutable
objects.

dblack

1/12/2007 10:58:00 PM

0