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

Reply via email to