[Newbies] Is there a Squeak idiom for array slices?

Bert Freudenberg bert at freudenbergs.de
Fri Dec 18 01:59:15 UTC 2009


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

- Bert -




More information about the Beginners mailing list