[Pharo-dev] Probably stupid... question about string printString.

Stephane Ducasse stepharo.self at gmail.com
Sun Oct 22 08:16:15 EDT 2017


Nicolas

the problem is that I do not know if I will get a string or an object.
the arg gets printStringed (instead of asString).
Now if I want to have the correct behavior I will have to type check.

Still I do not understand why printString a string wrap it
'foo' printString
evaluating to 'foo'
vs.
'foo' printString
evaluating to '''foo'''

There is something unclear to me around string representation and
object representation as string.


@Alistair
In fact we should use displayString to call a printString for UI (list...)


On Sat, Oct 21, 2017 at 10:10 PM, Nicolas Cellier
<nicolas.cellier.aka.nice at gmail.com> wrote:
> No. nextPutAll: self is not a good solution at all.
> Try it, and you'll get foo, not 'foo'.
>
> 'foo' printString has exactly 5 letters: $' $f $o $o $' so it does what you
> want.
>
> The problem is when you want to print 'foo' printString.
> You are in fact doing 'foo' printString printOn: aStream, IOW aStream
> nextPutAll: 'foo' printString printString.
>
>
> 2017-10-21 21:12 GMT+02:00 Stephane Ducasse <stepharo.self at gmail.com>:
>>
>> Yes this is my point. I was surprised to get ' on the transcript.
>>
>> Stef
>>
>> On Sat, Oct 21, 2017 at 7:49 PM, Alistair Grant <akgrant0710 at gmail.com>
>> wrote:
>> > On Sat, Oct 21, 2017 at 05:28:21PM +0200, Stephane Ducasse wrote:
>> >> Hi
>> >>
>> >> I would like to really understand why
>> >> 'foo' printString
>> >> >>>
>> >> '''foo'''
>> >>
>> >> and not why this is not
>> >>
>> >> 'foo'
>> >>
>> >> itself.
>> >>
>> >> Stef
>> >
>> > I can't comment on the original thinking behind this, but I agree that
>> > something like:
>> >
>> >
>> > String>>printOn: aStream
>> >         "Represent the receiver on the supplied stream"
>> >
>> >         aStream nextPutAll: self
>> >
>> >
>> >
>> > would be much better.
>> >
>> > If we're displaying values such as numbers and strings in a UI, e.g.
>> > table, we normally don't want the strings always enclosed in quotes.
>> >
>> > Cheers,
>> > Alistair
>> >
>> >
>>
>




More information about the Pharo-dev mailing list