On Dec 27, 2:15=A0pm, MonkeeSage <MonkeeS... / gmail.com> wrote:
> On Dec 27, 12:52 pm, Trans <transf... / gmail.com> wrote:
>
>
>
>
>
> > On Dec 27, 12:54 pm, MonkeeSage <MonkeeS... / gmail.com> wrote:
>
> > > On Dec 27, 9:55 am, Sebastian Hungerecker <sep... / googlemail.com>
> > > wrote:
>
> > > > George wrote:
> > > > > What would you expect this to do?
>
> > > > > =A0 [].last =3D 1
>
> > > > The same thing as "[][-1] =3D 1", I'd imagine.
> > > > The problem I'm seeing would be this: If you allow arr.last =3D x, y=
ou'd also
> > > > have to allow arr.last(n) =3D x if you want to be consistent, but th=
at's not
> > > > syntactically possible.
>
> > > > --
> > > > NP: Katatonia - Endtime
> > > > Jabber: sep... / jabber.org
> > > > ICQ: 205544826
>
> > > Agree. It's tempting to treat #first / #last as 0 / -1, but in
> > > actuality they are method calls and simply return a value; they don't
> > > subscript an array. Setting #last is not semantically different than
> > > [1,2,3].pop =3D 4, it's just that #last is just a bit more subtle.
>
> > I don't see what you are getting at here. #pop is destructive, #last
> > is not. What does #last return when it is called? It returns a
> > reference to the last element. So why would #last=3D do anything other
> > then set the reference of the last element? Seems obvious to me. So we
> > can't do last(n) =3D x, due to syntax constraints, oh well. It would
> > still be convenient to have the obvious n=3D1, no arg case. I find that
> > my programs are usually easier to read when I can use words rather non-
> > alphabetic symbols.
>
> > T.
>
> IOW, #pop returns a value, and this is just what #last does. One could
> argue that #last and #[-1] *should be* synonymous (which may be the
> point of the proposal); but as it currently stands, #last means the
> same thing as `def l(a); a[-1]; end` so it makes no sense to have a
> setter for it. Unless the semantics change, (to me at least) it is non-
> sense to have #last=3D. It's the same as a.pop =3D 3.
>
> Regards,
> Jordan- Hide quoted text -
>
> - Show quoted text -

no it is not!

irb(main):018:0> p an_array
[19, 5, 7, 11, 9, 3]
=3D> nil
irb(main):019:0> an_array.last
=3D> 3
irb(main):020:0> p an_array
[19, 5, 7, 11, 9, 3]
=3D> nil
irb(main):022:0> an_array.pop
=3D> 3
irb(main):023:0> p an_array
[19, 5, 7, 11, 9]
=3D> nil

Note that pop actually removes the last item

irb(main):025:0* an_array.pop =3D 3
NoMethodError: undefined method `pop=3D' for [19, 5, 7, 11, 9]:Array
        from (irb):25

irb(main):029:0> p an_array
[19, 5, 7, 11, 10]
=3D> nil
irb(main):030:0> an_array[-1] +=3D 1
=3D> 11
irb(main):031:0> p an_array
[19, 5, 7, 11, 11]

There's is no need for Array#last=3D or Array#first=3D

since you can simply use an_array[-1] +=3D 1 or an_array[0] +=3D 1