Collecting Smalltalk idioms

David T. Lewis lewis at mail.msen.com
Tue Aug 10 21:56:41 UTC 1999


On Tue, Aug 10, 1999 at 09:09:08AM -0400, Andrew C. Greenberg wrote:
> 
> In the silly Smalltalk tricks category, is there a "least ugly" way 
> to generate a comma separated list out of a collection?  The pithy:

This may be getting a bit repetitious, but I've used:

	aCollection inject: true into: [ :first :each |
		first ifFalse: [aStream nextPut: $,].
		each printOn: aStream.
		false]

Another way to do it is:

	(ReadStream on: aCollection) do: [ :each |
		each printOn: aStream.
		aStream atEnd ifFalse: [ aStream nextPut: $,]]

(This is from memory; hopefully I entered these right.)





More information about the Squeak-dev mailing list