[ANSI-Smalltalk] Behaviour of #collect:
Paolo Bonzini
bonzini at gnu.org
Wed Sep 24 06:51:46 BST 2008
> Of course there is another important reason to prefer
> #withAll:collect: in an addition to ANSI Smalltalk than
> #collect:as:. #withAll:collect: is a generalisation of
> a method (#withAll:) that DOES exist in ANSI Smalltalk.
> #collect:as: is a generalisation of the #as: method,
> which I grant you is a handy method, but it does NOT
> exist in ANSI Smalltalk.
>
> Whatever the original reason for adding aClass withAll: coll
> instead of the traditional coll as: aClass, that reason still
> applies to the combination of converting and transforming.
I've never seen #as:, though it was immediately clear what it is. But
"a as: b" can (must) be implemented "b withAll: a", but the converse is
not true -- because the dispatching has to be done on the class type to
distinguish variable-sized and arrayed collections.
> There is certainly no question of a single
> #collect:into: that could work for all or even many classes.
The same reason why #as: does not exist.
>> 2) Same species as receiver, if possible, otherwise send error to self.
>
> There is no notion of "species" in the ANSI Smalltalk standard.
Fully agreed that there is no reason for that. Furthermore, what would
the species be for a SortedCollection? A factory object that, when sent
#new/#new:, returns an object with the same sortblock as the original
collection? That's why some Smalltalks have #copyEmpty, #copyEmpty:,
#copyEmptyForCollect.
>> 8) as is (essentially case-by-case ad-hoc)
>
> I don't know what you mean by "as is". At the moment "as is"
> behaviour is generally *NOT* case-by-case ad-hoc, but standard.
> "As is", in fact, is pretty much 1 or 2.
"As is" is exactly 2, with the idea of species embedded in refinements
of the protocols.
Paolo
More information about the ANSI-Smalltalk
mailing list