[squeak-dev] Smalltalk string API

Eliot Miranda eliot.miranda at gmail.com
Mon Feb 21 18:47:57 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 ] ]
>

+1.  This is pellucidly clear and elegant.  It might not be super fast but
Marcus and I are working on adaptive optimization/speculative inlining
precisely to optimize cases like this into fast executable code.  Hopefully
we'll be able to demonstrate automatic optimization of code like this into
flatter faster code this year.  Keep writing beautiful code and somehow
we'll figure out how to make it go fast.


>
> 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/f0d7bcdc/attachment.htm


More information about the Squeak-dev mailing list