[squeak-dev] Smalltalk string API

Eliot Miranda eliot.miranda at gmail.com
Mon Feb 21 18:50:36 UTC 2011


On Sun, Feb 20, 2011 at 4:46 PM, Levente Uzonyi <leves at elte.hu> wrote:

> On Sun, 20 Feb 2011, Nicolas Cellier wrote:
>
> snip
>
>
>
>> Yes I know, I wrote this thing (before me Smalltalk was not mentionned).
>>
>
> Thanks.
>
>
>  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 |
>                self
>                        do: [ :each | each putOn: stream ]
>                        separatedBy: [ delimiter putOn: stream ] ]
>

Actually, thinking a little, why not


Collection >> join: delimiter

       ^self species streamContents: [ :stream |
               self
                       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++).
>
>
> Levente
>
>
>
>> 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
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20110221/52d9bcd9/attachment.htm


More information about the Squeak-dev mailing list