PS: *Neither* #flattened nor #flatCollect: can be blamed on
40 years of history.  #flatten(ed) arrived in Squeak back in
2015, at which time #flatCollect: did not exist.  In fact
there is *still* no #flatCollect: in Squeak, although Squeak
does have #gather:, since 2002.

#flatCollect: was added to Pharo more recently still,
as a new name for the tolerably well established #gather:,
apparently in the belief that it was a better name.
Given #flattened, it is not.  #gather: is not all that
helpful, but #flatCollect: is just wrong.  Even if
#flattened did not exist, the result of #flatCollect:
is generally not in any sense flat.

I repeat: NONE of this can be blamed on Smalltalk history.
#flattened was born crufty in 2015 and #flatCollect: is
a recent addition to Pharo.



On Thu, 14 Apr 2022 at 02:03, Richard O'Keefe <rao...@gmail.com> wrote:

> It would help to know which version of Pharo you are using.
> #(1 2 3) flatten
> raises an exception in Pharo 9 because there is no #flatten
> in Array's protocol.
> Collection has
>  #flatCollect:
>    -- #gather: was not a terribly helpful name,
>    -- but #flatCollect: is horribly misleading.
>  #flatCollect:as:
>    -- A misplaced method, should be
>    -- Collection class >> withAll: aCollection gather: aBlock
>  #flatCollectAsSet:
>    -- a trivial special case of #flatCollect:as:,
>    -- not clear why this special case exists.
>  #flattenOn:
>    -- aStream nextPutAll: self flattened
>    -- but without creating the intermediate data structure
>  #flattened
>    -- a curiously twisted "flatten" that does not work
>    -- at all for non-collections.
>
> #(1 2 3) flattened => #(1 2 3)
> 1 flattened => BOOM!
>
> By the way, we cannot blame the cruftiness of #flattened on
> 40 years of history.  #flatten/#flattened only entered Squeak
> about 7 years ago and it was BORN crufty.  I mistakenly thought
> Squeak and Pharo agreed on what it meant.  They do not.
> Squeak: puts it on SequenceableCollection and Stream.
> Pharo : puts it on Collection (more general) and not Stream (less so).
> Squeak: treats stream elements like nested collections.
> Pharo : doesn't.
> So my earlier claim bears repeating: of the Smalltalk systems that
> have some kind of flattening, no two agree on what it means.
>
> The one use I have ever had for flattening is to build up a
> large string by accumulating characters, strings, symbols,
> and sequences of the same in a sequence and then flattening
> the tree into a single string, which is something that
> Squeak and Pharo flatly refuse to do.
>
> One improvement I would like to see in Pharo 11 is for these
> methods to be deleted.
>
>

Reply via email to