[squeak-dev] #in: for collections

Steve Wessels steve at squeak.preeminent.org
Sat Dec 26 16:57:00 UTC 2009


"...
My first thought on reading the code was "Why the heck is he passing  
around arrays like that? Make it an object!"
..."

That's exactly what happened to me too, when reading the code.  In  
fact I started to (in my head) redesign the class method on the  
reciebet to just process a new object capturing this behavior.

- Steve

On Dec 26, 2009, at 10:08 AM, Colin Putney <cputney at wiresong.ca> wrote:

>
> On 2009-12-26, at 3:20 AM, Bert Freudenberg wrote:
>
>> ... however, #in: only works with single-argument blocks. Making  
>> #in: work with multi-arg blocks is of course possible but feels not  
>> right either. Does anybody have an idea for a better selector? Or  
>> another idea for how to code  this?
>
> I've occasionally mused that #do: and #in: ought to be the inverse  
> of each other. Object>>do: would behave like #in: and  
> Collection>>in: would evaluate the block with 'self anyOne' as the  
> parameter. With multi-arg blocks it could supply more elements, as  
> in your third example. On UndefinedObject, both methods would do  
> nothing. This would probably break a lot of code, so it's not really  
> feasible now, but if I could think of some other selectors that made  
> sense...
>
> Your idea here strikes me as similar to Ruby's splat operator, or  
> the way functional languages deal with lists by recursively  
> splitting them into head and tail. It feels like a really useful  
> idiom, and it would be nice to have it in Smalltalk, the same way we  
> have #ifTrue:ifFalse: rather than actual syntax for booleans.
>
>> In my example, "#getChannels" is an external library call returning  
>> an array, this is the code that converts the raw result into a  
>> proper object structure. You can argue that low-level code like  
>> this is okay to look like (2) but I'd say it doesn't have to ;)
>
>
> My first thought on reading the code was "Why the heck is he passing  
> around arrays like that? Make it an object!" Preaching to the choir,  
> I guess. :-)
>
> Colin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20091226/5494aba4/attachment.htm


More information about the Squeak-dev mailing list