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/ |
Hi Stef,
I think I do not understand the issue. Here is the screenshot of a Playground. ‘comics’ -> print-it -> ‘comics' What am I missing? Cheers, Doru On Feb 18, 2017, at 6:26 PM, stepharong <[hidden email]> 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, -- Using Opera's mail client: http://www.opera.com/mail/ MFElement.st (1K) Download Attachment |
Stef is right, there is something strange. Consider the following 4 expressions, each time with the result of 'Print It' inserted:
#foo->'foo'. "#foo->'foo'" (#foo->'foo') printString. "'#foo->''foo'''" 'foo'. "'foo'" 'foo' printString. "'''foo'''" In a Workspace (not Playground), the following happens: #foo->'foo'. #foo->'foo' #foo->'foo' printString. #foo->'''foo''' Which makes even less sense. > On 19 Feb 2017, at 09:06, stepharong <[hidden email]> 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 <[hidden email]> 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> |
In reply to this post by stepharong
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: In Pharo 3, we have this in a Workspace: 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: 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 <[hidden email]> wrote: -- www.tudorgirba.com www.feenk.com "Problem solving should be focused on describing the problem in a way that makes the solution obvious." |
I do not say that it is a problem of playground. I'm saying that our tools are breaking an important invariant. Printit should not produce "strings" that are not objects. What I'm saying it that - axiom one printString returns a string. - printIt send printString to the object and why does it no display a string except for objects whose representation is themselves. The problem not to put '' around string is that we get a broken things. In Pharo we have tools that when they should display a string return a "we do not know what" because it is not a literal! 'comics' Printit does not produce comics but 'comics' so why do we have (#AAA asClass new name: 'comics') printit because this is insane. It breaks everyrhing Stef Hi, -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by Tudor Girba-2
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.
> On 19 Feb 2017, at 10:59, Tudor Girba <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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." > > > > > |
On Sun, 19 Feb 2017 11:40:04 +0100, Sven Van Caekenberghe <[hidden email]>
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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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/ |
But this *is* a discussion about the tools, not the implementation.
ZnUrl is an example of class in the image that has a print representation like your object. So it looks like this (doing Print It in a Playground) (for me): 'https://pharo.org' asUrl. "https://pharo.org/" 'https://pharo.org' asUrl printString. "'https://pharo.org/'" But you seem to use a modification where the $" are not used ? I guess that the reason those $" are there is to make it a legal expression. Anyway, I do not see an underlying problem, only a possible discussion about what you would expect from the tools. Strings are poor representations, make them auto evaluate would make for much uglier text. I would not particularly like the following: 'https://pharo.org' asUrl. "ZnUrl fromString: 'https://pharo.org'" Or even: 'https://pharo.org' asUrl. "(ZnUrl fromString: 'https://pharo.org')" Though it is an option. (This goes for all similar objects, like date, time, ..). Then it does become a discussion about what a print string should be. > On 19 Feb 2017, at 11:42, stepharong <[hidden email]> wrote: > > On Sun, 19 Feb 2017 11:40:04 +0100, Sven Van Caekenberghe <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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/ |
Hi Sven,
It seems to me that we are now talking about double quote “. However, this is just a tool issue related to how to embed the result of Print It. Just to remove the confusion, please resend this message without the “comment” printing :). Cmd-p + Cmd+p gets the plain result embedded. Cheers, Doru > On Feb 19, 2017, at 12:14 PM, Sven Van Caekenberghe <[hidden email]> wrote: > > But this *is* a discussion about the tools, not the implementation. > > ZnUrl is an example of class in the image that has a print representation like your object. > > So it looks like this (doing Print It in a Playground) (for me): > > 'https://pharo.org' asUrl. "https://pharo.org/" > 'https://pharo.org' asUrl printString. "'https://pharo.org/'" > > But you seem to use a modification where the $" are not used ? > > I guess that the reason those $" are there is to make it a legal expression. > > Anyway, I do not see an underlying problem, only a possible discussion about what you would expect from the tools. > > Strings are poor representations, make them auto evaluate would make for much uglier text. > > I would not particularly like the following: > > 'https://pharo.org' asUrl. "ZnUrl fromString: 'https://pharo.org'" > > Or even: > > 'https://pharo.org' asUrl. "(ZnUrl fromString: 'https://pharo.org')" > > Though it is an option. (This goes for all similar objects, like date, time, ..). > > Then it does become a discussion about what a print string should be. > >> On 19 Feb 2017, at 11:42, stepharong <[hidden email]> wrote: >> >> On Sun, 19 Feb 2017 11:40:04 +0100, Sven Van Caekenberghe <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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 <[hidden email]> 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/ > > -- www.tudorgirba.com www.feenk.com "We can create beautiful models in a vacuum. But, to get them effective we have to deal with the inconvenience of reality." |
In reply to this post by stepharong
Hi Stef,
Just a clarification. I do not argue here. I just explain what I see. I think it was like this since a long time. I even checked in an old VW I have around and it seems to have the same behavior.
But, I do agree that it is not straightforward at all. It took me a while to figure this out and it is still confusing sometimes. In fact, this is why we have a String presentation in the String object - I needed something that clarifies situations like these. That does not mean it is the best solution :). On Feb 19, 2017, at 11:42 AM, stepharong <[hidden email]> wrote: It’s the other way around :). Example A: 'comics' >>print it>> ‘comics’ In this case we have a string object and we send printString to it which in String>>storeOn: adds the quotes as part of the contents of the new string. Example B: (#AAA asClass new name: 'comics') >>print it>> comics Here we have an non-string object and we sent printString to it which creates a string with the contents of the stream. As no String>>storeOn: is invoked in this case, there are no quotes. So, the two resulting print it strings do not have the same contents. Maybe another case: Example C: (#AAA asClass new name: 'comics’) printString >>print it>> ‘comics’ This is equivalent to Example A. We send printString to a string object and we get the quotes. The issue is that when we send printString to a string, we produce a new string with escaped quotes: 'comics' = (String streamContents: [:s | s << 'comics’]) contents. "true" 'comics' = (String streamContents: [:s | s << 'comics']) contents printString. "false" I'm sorry but I do not get it at all. Another thing to keep in mind is: Example D: Object new >>print it>> an Object This is essentially equivalent with Example A If Example B would produce >>print it>> ‘comics’ it would mean that Example D would produce >>print it>> ‘an Object’ Ugh, I already got dizzy with so many quotes :). One problem is that when you look at a string, you do not know how many String>>storeOn: commands it went through. So, here is an idea: what if String>>printString would produce a EscapedString, which behaves like an operator? In this case, we would see better how many levels of String>>storeOn: are being displayed. What do you think? Cheers, Doru StefOn 19 Feb 2017, at 10:59, Tudor Girba <[hidden email]> wrote: -- www.tudorgirba.com www.feenk.com "From an abstract enough point of view, any two things are similar." |
In reply to this post by stepharong
On 02/19/2017 04:37 AM, stepharong wrote:
> I do not say that it is a problem of playground. I'm saying that our > tools are breaking an important invariant. > Printit should not produce "strings" that are not objects. > > What I'm saying it that > - axiom one printString returns a string. > - printIt send printString to the object and why does it no > display a string > except for objects whose representation is themselves. > > The problem not to put '' around string is that we get a broken things. The tools aren't the ones putting the quotes around the string. Calling #printString on a String puts the quotes around the string. If you were to put quotes around other printString's then you would need to special case String to not put the quotes around twice. The current implementation looks right to me. #printString returns a string to help developers. #printString on some objects returns a string that when evaluated creates an equivalent object (e.g., String, Point, etc.). However, on other objects it returns a string that only helps the developer see what the object is (e.g., OrderedCollection). The trick is to know which object's printString can be evaluated and which are only for display. Of course, if you want a string that you can evaluate, you should use #storeString. John Brant |
In reply to this post by Tudor Girba-2
Hi doru Yes I know. I did not imply anything. I think that the current status is bogus. I do not see any scenario that makes printString not returning and displaying a string good. I do not get why 'comics' printString should double quote it. to me 'comics' printString >>> 'comics' 'comics' printIt >>> 'comics' as well as (#AAA asClass new name: 'comics') PrintIt I just to not get what is the benefit not to have in the workspace or any users of printIt no single quote I agree that for a list of items you do not want to have 'astroboy' 'tintin' but instead astroboy tintin I see that lot of people got confused about that. Just look at the cuboid videos of Roassal you get comboboxes full of ' ' while there should not have any. Now to me this is the job of displayString. displayString is not the same as printString. printString should return a string and I should see a string in the REPL Currently in the REPL because this is what we are talking about obtaining a non string is confusing. Am I clear? Stef Hi Stef, -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by John Brant-2
Hi John > The tools aren't the ones putting the quotes around the string. Calling > #printString on a String puts the quotes around the string. If you were > to put quotes around other printString's then you would need to special > case String to not put the quotes around twice. I do not understand your printString point. to me printString contract is: return a string to represent the receiver (not talking about self evaluating objects here). so why when I have (MFDirectory new name: 'comics') printIt I do not get why I do not get 'comics' but comics since printIt invokes printString? Now I probably broke myself this contract when I introduced self-evaluating objects. true printIt >>> true is probably wrong. May be printIt is the wrong name. May be this is displayResult I do not know there is something confusing. I'm confuse ;( > The current implementation looks right to me. #printString returns a > string to help developers. #printString on some objects returns a string > that when evaluated creates an equivalent object (e.g., String, Point, > etc.). I did the self-evaluating behavior and I'm thinking that may be this is wrong and that we should always get a string not matter what happens. > However, on other objects it returns a string that only helps the > developer see what the object is (e.g., OrderedCollection). The trick is > to know which object's printString can be evaluated and which are only > for display. This is where I think that displayString is different than printString and that printString no matter what should be consitent I should return a string and the tools like the repl should display such as a string. This is also where > Of course, if you want a string that you can evaluate, you should use > #storeString. > > > John Brant > -- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by stepharong
On Sun, 19 Feb 2017 16:04:31 +0100, stepharong <[hidden email]> wrote:
Yes there is one: the self evaluating objects 1 printIt >>> 1 true printIt >>> true true printString printIt >>> 'true' now I'm confused because there is something that does not work.
-- Using Opera's mail client: http://www.opera.com/mail/ |
In reply to this post by stepharong
On Sun, Feb 19, 2017 at 1:26 AM, stepharong <[hidden email]> 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 > | printString | > self > evaluateSelectionAndDo: [ :result | > printString := [ result printString ] > on: Error > do: [ '<error in printString: try ''Inspect > it'' to debug>' ]. > self afterSelectionInsertAndSelect: printString ] btw, the code you reference there does not get executed from Playground. This does... (GLMGenericAction new) title: 'Print it'; action: [ :aPresentation | aPresentation printSelection ]; keymap: PharoShortcuts current printItShortcut; yourself. from GLMRubricSmalltalkCodePresentation>>executionSelectionActions which announces GLMPrintSelection leading to GLMMorphicPharoScriptRenderer>>evaluateAndPopPrintHighlight GLMPrintPopper installAlarm: #popupPrint for: self GLMMorphicPharoCodeRenderer>>popupPrint "Evaluates selected code and prints it in a popper" textMorph textArea editor highlightEvaluateAndDo: [ :result | textMorph shoutStyler style: textMorph text. GLMPrintPopper new openFromRubric: textMorph textArea withResult: result ] cheers -ben |
In reply to this post by stepharong
On 02/19/2017 09:14 AM, stepharong wrote:
> > Hi John > >> The tools aren't the ones putting the quotes around the string. >> Calling #printString on a String puts the quotes around the string. If >> you were to put quotes around other printString's then you would need >> to special case String to not put the quotes around twice. > > I do not understand your printString point. > to me printString contract is: return a string to represent the receiver > (not talking about self evaluating objects here). > > so why when I have > > (MFDirectory new name: 'comics') printIt > > I do not get why I do not get > 'comics' but comics > since printIt invokes printString? If I understand your code correctly, I think the printOn: method (invoked from printString) is calling Stream>>#<<. That method calls String>>#putOn: which calls Stream>>#nextPutAll:. That method just puts every character in the string on the stream. Now, when you invoke String>>#printString, it calls String>>#printOn: which calls String>>#storeOn:. #storeOn: adds the beginning and ending quotes (as well as doubling any quotes in the middle of the string). The printString of a string is never equal to itself since it is adding the quotes: 'a' printString = 'a' "false" However, when compiled it is equal: (Compiler evaluate: 'a' printString) = 'a' "true" > Now I probably broke myself this contract when I introduced > self-evaluating objects. > > true printIt >>>> true is probably wrong. > > May be printIt is the wrong name. > > May be this is displayResult > > I do not know there is something confusing. > > I'm confuse ;( You are not printing the string, you are printing an object which creates a string and that string is then displayed. Displaying a string doesn't add the extra quotes like printing a string does. What should be the first character of the printString of true? To me, if you have it being a quote ('), then it is wrong. The printString of true should be true (in Smalltalk literal string format 'true'). However, having the first character of a printString of a string be a quote makes it easier for me as a developer to see that the object that was printed was a string and not something else. If I didn't want the quote, then I should have probably used the displayString method. >> The current implementation looks right to me. #printString returns a >> string to help developers. #printString on some objects returns a >> string that when evaluated creates an equivalent object (e.g., String, >> Point, etc.). > > I did the self-evaluating behavior and I'm thinking that may be this is > wrong and that > we should always get a string not matter what happens. > >> However, on other objects it returns a string that only helps the >> developer see what the object is (e.g., OrderedCollection). The trick >> is to know which object's printString can be evaluated and which are >> only for display. > > This is where I think that displayString is different than printString > and that > printString no matter what should be consitent > I should return a string and the tools like the repl should display such > as a string. It is consistent. #printString returns a string. That string is then displayed. Displaying a string just puts the characters on the display without adding anything else. I think your confusion may be that printString on a string object returns another string with quotes that when evaluated returns another string equivalent to the original. What characters #printString puts in the string is up to the developer. It should be what they think is important to display when developing the code. For strings, someone decided that it would be good to return another string that when evaluated would return an equivalent string. This is not necessary -- it could have just returned itself. However, I think the choice was a good one as developers can more easily see when something is a string vs. some other object. John Brant |
Free forum by Nabble | Edit this page |