-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revisit toString #499
Comments
Need to consider how this relates to #159. |
Also related to #135. |
New design is as follows. The spec would define an abstract operation ToString(v, style), where three styles are supported:
This design is similar to Python:
Python doesn’t have the third style; this leads to weirdness when applying str(x) to collections, in that the members are output in a way that has an inappropriate level of detail. The A new
These functions should be robust in the presence of cycles. The implementation of toString would have a stack of the structures/objects that are being converted; toString when applied to some object, would first check whether the object is on the stack; if so, then there’s a cycle; otherwise, when it calls toString on members, it does so with itself added to the top of the stack. For now, we have the limitation that there is no mechanism for user-defined toString on objects to deal with cycles. The following table summarizes the behaviour of the abstract operation ToString(v, style)
|
@jclark
Is the expected value of
For the example given below,
can this be the expected outcome?
|
The entry for error in the table isn't quite right: I just edited it. Note that your syntax is no longer right in Swan Lake. It's
The toString output should look like the constructor:
Specifically:
The expression style includes the module name in the distinct type-id. |
@jclark a quick clarification on map. Does map contains a space after after the ":" (and before) the value?, For example, {"name": "Jane", "age": 25, "spouse": "John", "gender": "female"} |
I definitely wouldn't put a space before
as you wrote, or
I slightly prefer with spaces for readability. Which do you prefer? |
Actually I prefer the second option which you suggested (without spaces), just intuitive. But shall we make a quick decision on this because there are some dependent changes pending? |
I don’t have a strong opinion and I don’t think it matters very much. Do whichever the implementation team prefers and let me know which you decide. |
Sure James. We are moving forward with the option #2 (without spaces). |
OK, I updated the table above accordingly: toString for error also should not add space after string. |
Given we are doing 2.0, I think we should revisit the design of
toString
to see if we can come up with something that works better than our current approach.The text was updated successfully, but these errors were encountered: