[Pharo-dev] confused about printString and printIt

stepharong stepharong at free.fr
Sun Feb 19 05:42:37 EST 2017


On Sun, 19 Feb 2017 11:40:04 +0100, Sven Van Caekenberghe <sven at stfx.eu>  
wrote:

> Ah, you're right: there is a difference between printing a textual  
> representation on a stream / window and doing the same with the actual  
> (print)string. I was not yet fully awake I guess.

So 	
	'comics'
	>>> comics 				whatever it means
but
	(#AAA asClass new name: 'comics')
	>>> 'comics'

I'm sorry but I do not get it at all.
Especially since we always wrote that printIt is sending printString.
I find that totally broken and I do not understand why this is good.

Stef




>
>> On 19 Feb 2017, at 10:59, Tudor Girba <tudor at tudorgirba.com> wrote:
>>
>> Hi,
>>
>> Hmm, I think I do not see it :).
>>
>> Let’s take it slowly. From what I see, the behavior is the same since  
>> at least Pharo 3.
>>
>> Here is a script that seems to reproduce your situation:
>>
>> Object subclass: #AAA
>> 	instanceVariableNames: 'name'
>> 	classVariableNames: ''
>> 	package: 'AAA'.
>> #AAA asClass compile: 'printOn: aStream
>>     aStream << name'.
>> #AAA asClass compile: 'name: aString
>> 	name := aString'.
>> #AAA asClass new name: 'comics'
>>
>> In Pharo 6, we have in a Playground:
>>
>> <Screen Shot 2017-02-19 at 10.48.55 AM.png>
>>
>> In Pharo 3, we have this in a Workspace:
>>
>> <Screen Shot 2017-02-19 at 10.49.26 AM.png>
>>
>> Calling Print It on an object produces a string out of the contents of  
>> the stream, and displaying it shows the contents of the stream (so, no  
>> quotes). Calling Print It on a string produces a string of the string,  
>> and displaying it shows the quotes of the first string.
>>
>> You can see this in the String tab of the inspector:
>>
>> <p1.png>
>>
>>
>> <p2.png>
>>
>> Does this make sense?
>>
>> I think this is not inconsistent, but maybe there is a better way. In  
>> any case, the behavior seems to exist since a long time.
>>
>> Cheers,
>> Doru
>>
>>
>>> On Feb 19, 2017, at 9:06 AM, stepharong <stepharong at free.fr> wrote:
>>>
>>> Hi doru
>>>
>>> may be I do not see the obvious.
>>> I defined a class
>>>
>>> Object subclass: #MFElement
>>>     instanceVariableNames: 'name parent'
>>>     classVariableNames: ''
>>>     package: 'MyFS2'
>>>
>>> printOn: aStream
>>>     parent isNil ifFalse: [ parent printOn: aStream ].
>>>     aStream << name
>>>
>>> name: aString
>>>      name := aString
>>>
>>>
>>> MFDirectory new name: 'comics'.
>>>
>>>
>>> And when I do
>>>
>>>
>>> (MFDirectory new name: 'comics')
>>> comics/
>>>
>>>
>>> (MFDirectory new name: 'comics') printString
>>>>>> 'comics/'
>>>
>>>
>>> Hi Stef,
>>>
>>> I think I do not understand the issue.
>>>
>>> Here is the screenshot of a Playground.
>>>
>>> ‘comics’ -> print-it -> ‘comics'
>>>
>>> <Mail Attachment.png>
>>>
>>> What am I missing?
>>>
>>> Cheers,
>>> Doru
>>>
>>>
>>>> On Feb 18, 2017, at 6:26 PM, stepharong <stepharong at free.fr> wrote:
>>>>
>>>>
>>>> Hi guys
>>>>
>>>> I'm working on an introduction chapter for my future book and I do  
>>>> not like the behavior I see in latest pharo 60.
>>>>
>>>> And I do not understand the behavior of print-it
>>>>
>>>> (MFDirectory new name: 'comics')
>>>> comics/
>>>>
>>>>
>>>> (MFDirectory new name: 'comics') printString
>>>>>>> 'comics/'
>>>>
>>>>
>>>> Why print it does not produce ''?
>>>>
>>>>
>>>> Stef
>>>>
>>>>
>>>> printIt
>>>> 	"Treat the current text selection as an expression; evaluate it.  
>>>> Insert the
>>>> 	description of the result of evaluation after the selection and then  
>>>> make
>>>> 	this description the new text selection."
>>>>
>>>> 	| printString |
>>>> 	self
>>>> 		evaluateSelectionAndDo: [ :result |
>>>> 			printString := [ result printString ]
>>>> 				on: Error
>>>> 				do: [ '<error in printString: try ''Inspect it'' to debug>' ].
>>>> 			self afterSelectionInsertAndSelect: printString ]
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Using Opera's mail client: http://www.opera.com/mail/
>>>>
>>>
>>> --
>>> www.tudorgirba.com
>>> www.feenk.com
>>>
>>> "It's not how it is, it is how we see it."
>>>
>>>
>>>
>>>
>>> --
>>> Using Opera's mail client: http://www.opera.com/mail/
>>> <MFElement.st>
>>
>> --
>> www.tudorgirba.com
>> www.feenk.com
>>
>> "Problem solving should be focused on describing
>> the problem in a way that makes the solution obvious."
>>
>>
>>
>>
>>
>


-- 
Using Opera's mail client: http://www.opera.com/mail/



More information about the Pharo-dev mailing list