On Nov 4, 2:13=A0pm, Seebs <usenet-nos... / seebs.net> wrote:
> On 2009-11-04, RichardOnRails <RichardDummyMailbox58... / USComputerGurus.c=
om> wrote:
>
> > class Fixnum
> > =A0 def pp # We can?t define ++ because of a compiler restriction.
> > =A0 =A0 self + 1
> > =A0 end
> > end
>
> This doesn't seem to do the right thing.
>
> a =3D 1
> a.pp
>
> Is a now 2? =A0If not, you haven't implemented an increment operator.
>
> > Appending these =A0lines shows that a & b values are distinct.
> > That is, =A0after incrementing, =A0a =3D2, =A0b is unchanged; b is not
> > impacted by a?s change
> > a +=3D 1; show (a) =A0=3D> =A0Got 2; =A0class =3D Fixnum; =A0 object_id=
 =3D 5; =A0v >> 1
> >=3D 2
> > show (b) =A0=3D> =A0Got 1; =A0class =3D Fixnum; =A0 object_id =3D 3; =
=A0v >> 1 =3D 1
>
> Right. =A0You've changed which object a refers to, because you've reassig=
ned
> a.
>
> > Appending these =A0lines shows the ++?s alias pp works just find
> > a=3D1; show(a.pp) =A0=3D> =A0Got 2; =A0class =3D Fixnum; =A0 object_id =
=3D 5; =A0v >> 1
> >=3D 2
> > show(b) =A0=3D> =A0Got 1; =A0class =3D Fixnum; =A0 object_id =3D 3; =A0=
v >> 1 =3D 1
>
> Not the same. =A0The key is that, after "a +=3D 1", not only do you get 2=
,
> but a is now 2.
>
> > Do you agree?
>
> No.
>
> For "a.pp" to be the same as a++ in other languages, you'd have to do:
>
> a =3D 1; a.pp; show(a) =3D> Got 2
>
> If you don't get a "2" by using a.pp, it's not an increment, just a "one
> more than".
>
> Consider a loop:
>
> a =3D 1
> while ((a +=3D 1) < 10) do
> =A0 puts a
> end
>
> Now, try:
>
> a =3D 1
> while (a.pp < 10) do
> =A0 puts a
> end
>
> Doesn't do the same thing.
>
> -s
> --
> Copyright 2009, all wrongs reversed. =A0Peter Seebach / usenet-nos...@see=
bs.nethttp://www.seebs.net/log/<-- lawsuits, religion, and funny picturesht=
tp://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Hi Peter,

> This doesn't seem to do the right thing.
>
> a =3D 1
> a.pp
>
> Is a now 2?  If not, you haven't implemented an increment operator.

Thanks for this question.  You're so right.  I couldn't see it until
you pointed it out.

class Fixnum
  def pp # We can=92t define ++ because of a compiler restriction.
    self + 1
  end
end

doesn't change self (which Ruby won't allow for Fixnum's!!!  Which, of
course, is why your:

a =3D 1
while (a.pp < 10) do
  puts a
end

produces an infinite number of 1's ..., or would if RAM were infinite
and hardware addressing mechanisms were infinite.

I grateful for you taking the time to identify my deficiencies.

Best wishes,
Richard