[Newbies] Is there a Squeak idiom for array slices?
digitig at gmail.com
Fri Dec 18 11:06:03 UTC 2009
2009/12/18 Bert Freudenberg <bert at freudenbergs.de>:
> On 18.12.2009, at 02:51, Bert Freudenberg wrote:
>> On 18.12.2009, at 02:47, Tim Rowe wrote:
>>> If, for example, variable a contains an array with 20 elements, but I
>>> want to inject:into: just elements 3 through 17, is there an easier
>>> way than step-by-step creating a new array, copying the required
>>> elements of a into it, and then doing an inject:into: on that?
>> array atAll: (3 to: 17)
> Though that's not really an idiom, I don't think I've ever seen that used in code. #atAll: can provide an arbitrary mapping.
> More efficient and more often used are these
> array copyFrom: 3 to: 17
> array first: 4
> array last: 5
> array allButFirst: 6
> array allButLast: 7
Many thanks -- I'll certainly be able to o what I want to with
something from that list.
More information about the Beginners