From: MonkeeSage Date: 2007-12-30T08:24:58+09:00 Subject: Re: Add Array#first= and Array#last= to std lib On Dec 27, 1:58 pm, Sebastian Hungerecker wrote: > MonkeeSage wrote: > > On Dec 27, 1:38 pm, Sebastian Hungerecker wrote: > > > MonkeeSage wrote: > > > > IOW, #pop returns a value, and this is just what #last does. > > > > How is [] different in that regard? That only returns a value, too. > > > Exactly. It's not... [] = 3 => syntax error... > > That [] there is an emtpy array. That's not the [] I was talking about. > I'm sorry if I wasn't clear, let me rephrase: > You seemed to say that while there is a method Array#[]= (which I assume, > you're ok with, since you haven't stated otherwise), there shouldn't be a > method Array#last= since Array#last only returns a value like Array#pop does. > Now my question to you is: How is Array#[] different in that regard than > Array#last? I mean some_array[-1] also only returns a value. But you don't > have a problem with people being able to write some_array[-1] = some_value > do you? > > -- > Jabber: sep...@jabber.org > ICQ: 205544826 Sebastian (and Robert), I guess I wasn't being very clear. By saying that #last just returns a value like #pop, my point was that #last is the semantic equivalent of the example I gave: "def l(a); a[-1]; end". I should have probably compared it to #length rather than #pop since #pop is destructive. I wasn't arguing for or against #last=, per se; I was only trying to explain why it doesn't make sense, _to me_, "Unless the semantics [of #last] change," to have #last=. I.e., #[] subscripts the array and returns the value of the index, but #last returns the value of subscripting the array at index #length-1; it is another level of abstraction removed from #[]; so with those semantics, #last= would be like #length= (or #pop=), and you end up with exceptions when the value is immutable. Regards, Jordan