select: refactoring (visits an old question/discussion)

Brian Rice water at tunes.org
Mon Nov 29 18:50:08 PST 2004


It was asked a few months ago why select: on Arrays didn't "shrink" the 
result array to the number of elements left and instead kept them in 
the same position.

E.g. {1. 2. 3} select: [| :x | x > 2] => {Nil. Nil. 3}

My rationale at the time came from Smalltalk-80 gurus' advice to the 
effect that select: should behave for maps and sequences in the same 
way. Of course, Slate's Array reader select: (using a stream 
in-between) always worked, but over time we realized that this just 
wasn't a practical default to present to people. Also, we'd never 
bothered to make ExtensibleSequences have this same behavior, so they 
had resized-solutions, and so there was an inconsistency.

So, some time ago we changed this (oops, basically I was going to 
announce this and then the big inheritance refactoring came up): now, 
"non-moving select:" is mapSelect: and works on dictionaries, 
sequences, and other maps (such as trees with keys). select: on arrays 
(and as always for other sequences) now answers {3} for the expression 
above.

Enjoy!

--
Brian T. Rice
LOGOS Research and Development
http://tunes.org/~water/




More information about the Slate mailing list