[squeak-dev] Smalltalk string API

Levente Uzonyi leves at elte.hu
Mon Feb 21 00:46:25 UTC 2011

On Sun, 20 Feb 2011, Nicolas Cellier wrote:


> Yes I know, I wrote this thing (before me Smalltalk was not mentionned).


> Maybe it was a bit late at night ;) , anyway I had not so many choices:
> - use join: (I think it is integrated in Pharo)

I don't like that implementation. To me it's overengineered and 
unintuitive. The following is enough for most of cases IMHO:

Collection >> join: delimiter

 	^String streamContents: [ :stream |
 			do: [ :each | each putOn: stream ]
 			separatedBy: [ delimiter putOn: stream ] ]

This reflects my preference (receiver is the collection, argument is the 
delimiter) and is not compatible with Pharo's implementation.

> - use String streamContents: [:stream | arrayOfStrings do:
> [:eachString | stream nextPutAll: eachString] separatedBy: [stream
> nextPutAll: separator]]
>  I would have written this form in Smalltalk, however I find the
> periphrase a bit long versus other languages

I see you updated the page, and yes, the phrase is pretty long compared to 
other languages'.

> - use reduce: to find a shorter form comprehensible by foreign
> programming language users, though not optimal

#reduce: combined with #, may give the impression to outsiders that 
strings have dynamic implementation (like in C++).


> Of course, it would also be nice to see a Xtreams solution.
> Nicolas
>> *http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(string_functions)#join
>>> Cheers

More information about the Squeak-dev mailing list