2007/12/28, Sebastian Hungerecker <sepp2k / googlemail.com>:
> Robert Klemme wrote:
> > I do not see why allowing last= would make lasts(n)= necessary.
>
> For consistency. I believe that any method foo= should be equivalent to the
> method foo except for the fact that it sets the value instead of getting it,
> which in this case isn't possible (without changing the language). I mean,
> that's not a major problem, but it'd feel a tad incosistent to me.

You're right. Actually I was not aware that you could actually use an
argument with last. Thanks for pointing that out!

And I agree, that changes the situation a bit.  As a workaround you
could implicitly use the number of elements when assigning an Array
but I doubt it's a good idea.  What if you wanted the last element to
be that array and not replace the last n elements?  That situation
could not be distinguished. Hm...

Re your other posting: yes, making last= behave like [-1]= is
certainly a good idea.  So it's "throw an exception".

irb(main):004:0> a=[]
=> []
irb(main):005:0> a[-1]=123
IndexError: index -1 out of array
        from (irb):5:in `[]='
        from (irb):5
        from :0

Also a tad inconsistent:

irb(main):006:0> a[0]=123
=> 123
irb(main):007:0> a
=> [123]

So at least I now have an idea why last= is absent from the std lib.
So the discussion was definitively worthwhile.

Kind regards

robert

-- 
use.inject do |as, often| as.you_can - without end