[squeak-dev] Noob question: array slice?

Travis Griggs travisgriggs at gmail.com
Fri Aug 6 07:08:10 UTC 2010


On Aug 5, 2010, at 11:03 PM, Casey Ransberger wrote:

> Given that I have a collection like #(foo bar baz 1 2 3), and I want  
> to get elements 2...4, what selector do I use? I'm confused. Argh.  
> Seems like I should be able to figure this out by now without what I  
> think of being a pain. I guess I can just test the bounds, but yuck.


#(foo bar baz 1 2 3) copyFrom: 2 to: 4

? is that what what you mean?

another way, more general would be

(2 to: 4) collect: [:n | original at: n]

In VisualWorks 7.7.1, we added a Subsequence object, that can act as a  
subrange facade to a sequence. It's very very handy for the Meyer diff  
algorithm, and doing Text differencing.

Subsequence sequence: #(foo bar baz 1 2 3) from: 2 to: 4

You can stack them of course.

--
Travis Griggs
Objologist
For every adage, there is an equal and contrary un-adage




More information about the Squeak-dev mailing list