Re: Ruby doesn't implement x++ for Fixnum's because ???
by Rick DeNatale other posts by this author
Nov 8 2009 10:50AM messages near this date
Re: Ruby doesn't implement x++ for Fixnum's because ???
|
Re: Ruby doesn't implement x++ for Fixnum's because ???
On Sun, Nov 8, 2009 at 1:18 PM, Tony Arcieri <tony@[...].com> wrote:
> On Sun, Nov 8, 2009 at 10:45 AM, Rick DeNatale <rick.denatale@[...].com>wrote:
>
> > As Matz himself has pointed out in this thread,
> >
> > >
> > > There's no way to modify local variables by sending message in Ruby.
> > >
> > > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mat
z.
> >
> > Which is something I've said on this thread before (multiple times IIRC).
> >
> > This has nothing to do with whether or not the object bound to a
> > variable is immutable, it has to do with how ruby variable bindings
> > can and cannot be changed, and that is the whole point.
> >
>
> You still seem to be missing what I'm proposing.
>
> For Numerics, ++ would rebind. Â For everything else, it would be dispatched
> as a message.
>
> Am I being unclear?
No, but you ARE missing the fact that the lack of being able to rebind
a variable via a method has NOTHING to do with the class of the object
which is currently bound to that variable.
Since ruby variables aren't typed then the expansion of the syntactic sugar
b = a++
to "rebind for Numerics and dispatch for everything else" would have
to be something like
if Number === a
b, a = a, a.succ
else
#....
end
But note that in order to add 1 to a number, we still need to dispatch
a method whether that be succ, or + and if we are going to do that we
might just as well expand b = a++ to
b, a = a, a.succ
no matter what a is currently bound to.
Not that I think ++ is valuable enough to change the language.
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Thread:
RichardOnRails
Gavin Sinclair
Marnen Laibow-Koser
Tony Arcieri
David A. Black
T3ch.Dude
TonyMc
Tony Arcieri
James Edward Gray II
Seebs
Aldric Giacomoni
Sebastian Hungerecker
Aldric Giacomoni
Seebs
Seebs
Joshua Ballanco
Michael W. Ryder
Seebs
Rick DeNatale
Marnen Laibow-Koser
Aldric Giacomoni
Marnen Laibow-Koser
Aldric Giacomoni
Rick DeNatale
Aldric Giacomoni
Rick DeNatale
Aldric Giacomoni
Rick DeNatale
David A. Black
Aldric Giacomoni
Marnen Laibow-Koser
Marnen Laibow-Koser
Seebs
Seebs
Seebs
Gavin Sinclair
Tony Arcieri
Joel VanderWerf
Tony Arcieri
Marnen Laibow-Koser
Aldric Giacomoni
Tony Arcieri
Aldric Giacomoni
Phrogz
Ralph Shnelvar
Tony Arcieri
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Joshua Ballanco
Tony Arcieri
Seebs
Tony Arcieri
Seebs
Tony Arcieri
Tony Arcieri
Seebs
Seebs
RichardOnRails
David A. Black
Marnen Laibow-Koser
Seebs
Tony Arcieri
Rick DeNatale
Tony Arcieri
Rick DeNatale
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
Walton Hoops
Tony Arcieri
Walton Hoops
Tony Arcieri
Florian Assmann
Marnen Laibow-Koser
Walton Hoops
Seebs
David A. Black
Gavin Sinclair
Gavin Sinclair
Gavin Sinclair
Tony Arcieri
David A. Black
Tony Arcieri
David A. Black
Yukihiro Matsumoto
Seebs
RichardOnRails
RichardOnRails
Martin DeMello
Aldric Giacomoni
Seebs
RichardOnRails
RichardOnRails
David A. Black
Seebs
Rick DeNatale
Seebs
Seebs
Lith
Gavin Sinclair
Tony Arcieri
Walton Hoops
Michael W. Ryder
Walton Hoops
Michael W. Ryder
Marnen Laibow-Koser
Walton Hoops
Michael W. Ryder
Walton Hoops
Matthew K. Williams
Marnen Laibow-Koser
Michael W. Ryder
David A. Black
David A. Black
Michael W. Ryder
Marnen Laibow-Koser
Tony Arcieri
Marnen Laibow-Koser
Tony Arcieri
David A. Black
Aldric Giacomoni
Martin DeMello
Tony Arcieri
Tony Arcieri
Martin DeMello
Paul Smith
Tony Arcieri
Seebs
Rick DeNatale
|