[ENH] Minor collection improvements
Andrew C. Greenberg
werdna at gate.net
Sat Sep 11 11:08:20 UTC 1999
>2)
>
> #($a $b $c $d $e) asString
>
>yields:
>
> '($a $b $c $d $e)'
>
>I think it should really yield 'abcde'.
I used to think so as well, until I realized that the principal use
of asString was not so much for conversion per se, but for
facilitating printing and reporting, such as with Transcript>>#show:
or with a variation of #printOn:. For these purposes, the "old"
answer is really more appropriate, as an array of characters is NOT
the same as a string. The difficult is the overloading of the
meanings for asString.
What is more, not all forms of:
anArray asString
properly coerce to a string as described. For example:
#(true 1 0 $a #stuff 'more stuff') asString
to me should answer
'#(true 1 0 $a #stuff 'more stuff')'
and not
'true10$a#stuff''more stuff'''
or an error.
Particularly since there is an idiom for producing the desired string
in the special case of a homogenous array of Character:
String streamContents: [:s | anArray do: [:ch | s nextPut: ch]]
I think that the present situation is probably better than special
casing homogenous arrays of chars, given the overloading of #asString.
More information about the Squeak-dev
mailing list
|