Skip to content
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

Improve REPL display of String values #8603

scabug opened this issue May 19, 2014 · 3 comments

Improve REPL display of String values #8603

scabug opened this issue May 19, 2014 · 3 comments


Copy link

@scabug scabug commented May 19, 2014

Copied from SUGGEST-30:

In Scala REPL (interactive interpreter), type this:

scala> Set(1, "1.2")
res11: scala.collection.immutable.Set[Any] = Set(1, 1.2)

The result does not put a quote on "1.2". Then the user cannot easily see what type each member is in the set. In addition, for the following:

scala> Set(1, "1.2 ")
res15: scala.collection.immutable.Set[Any] = Set(1, "1.2 ")

Quotes are added for string with leading/trailing whitespaces. This adds inconsistency. Also considering the following:

scala> Set(1, "1.2, 55")
res18: scala.collection.immutable.Set[Any] = Set(1, 1.2, 55)

Isn't the result confusing?

Please consider always adding quotes on strings in REPL result. Thank you.

PS: Original google group post for this issue is here:!topic/scala-user/xiXpEsCtnoA

Copy link

@scabug scabug commented May 19, 2014

Imported From:
Reporter: @som-snytt
Affected Versions: 2.11.0
See #6592

Copy link

@scabug scabug commented May 19, 2014

@som-snytt said:
Example confusion, compounded by quoting.

Copy link

@scabug scabug commented Apr 19, 2015

Li Haoyi (lihaoyi) said:
This is fixed in the Ammonite REPL

@  Set(1, "1.2")
res8: scala.collection.immutable.Set[Any] = Set(1, 1.2)
@ Set(1, "1.2 ")
res9: scala.collection.immutable.Set[Any] = Set(1, 1.2 )
@ Set(1, "1.2, 55")
res10: scala.collection.immutable.Set[Any] = Set(1, 1.2, 55)
@ Set("1", "1.2")
res11: scala.collection.immutable.Set[java.lang.String] = Set("1", "1.2")
@ Set("1", "1.2 ")
res13: scala.collection.immutable.Set[java.lang.String] = Set("1", "1.2 ")
@ Set(1, 1.2)
res12: scala.collection.immutable.Set[Double] = Set(1.0, 1.2)

As you can see, Set[Any] behavior still isn't great, but most people don't deal with Anys much anyway. Set[T] for any strongly-typed T is pretty-printed properly in the same way a literal would be written

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

1 participant
You can’t perform that action at this time.