[ANSI-Smalltalk] Behaviour of #collect:
Richard O'Keefe
ok at cs.otago.ac.nz
Wed Sep 24 06:00:33 BST 2008
On 23 Sep 2008, at 7:16 pm, Peter van Rooijen wrote:
> 1) Would adding #withAll:collect: to every class that has #withAll:
> be considered a good move?
>
> Are you talking about a general method on Collection class that
> would be essentially this?
>
> Collection class>>#collect: monadicBlock from: collection
> | elements |
> elements := OrderedCollection new
> .
> collection do: [:x | elements add: (monadicBlock value: x)]
> .
> ^self withAll: elements
With the exception that this doesn't come close to working for
dictionaries, yes.
> 2) What exactly should #collect: do when sent to an object that
> belongs to a class whose instances cannot hold the results that
> the block returns?
>
> This seems like a hard one, practically. Whatever current
> implementations do, would be hard to change. If we want a standard
> that is accepted, we probably shouldn't try to go that way. But
> isn't the upside that the problem becomes kinda moot with the
> addition of the class method discussed above?
"hard to change" in the sense that it might be difficult to get
AGREEMENT to change, yes.
"hard to change" in the sense that it would be difficult for
implementors do actually carry out the change,
far from it.
I've done it in Squeak, Ambrai Smalltalk, and Visual Works.
I am prepared to donate the code.
No, the problem doesn't become moot with the addition of
#withAll:collect:
because you have to KNOW that you need it, and Smalltalk is all about
NOT
having to know stuff like that. You would now be able to fix mysterious
and absurd crashes once you'd diagnosed the problem, but they would
still
happen.
> I think your idea is valid (and I don't see why it would be long
> winded and limiting). I like Eliot's proposed name better. Does
> someone see a problem with this? If not, I'd like to propose to add
> this to the new standard.
>
I have a very serious with Eliot's proposed name.
It's worse than "not intention-revealing"; because of existing uses
of "from:" in ANSI Smalltalk it is actively misleading.
It also puts the arguments in what is very definitely the wrong order.
As a general guideline, the block should come last.
It fails to highlight the commonalty with #withAll:,
c withAll: coll
is the same as
c withAll: coll collect: [:each | each]
More information about the ANSI-Smalltalk
mailing list