[SI-8603] Improve REPL display of String values Created: 19/May/14  Updated: 01/Nov/16

Status: Open
Project: Scala Programming Language
Component/s: Repl / Interpreter
Affects Version/s: Scala 2.11.0
Fix Version/s: Backlog

Type: Improvement Priority: Major
Reporter: A. P. Marki Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: community

Issue Links:
Cloners
clones SUGGEST-30 String in REPL result should be consi... CLOSED
Relates
relates to SI-6592 Unexpected result of scala.io.Source.... CLOSED

 Description   

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:
https://groups.google.com/forum/#!topic/scala-user/xiXpEsCtnoA



 Comments   
Comment by A. P. Marki [ 19/May/14 ]

Example confusion, compounded by quoting.

Comment by Li Haoyi [ 19/Apr/15 ]

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 `Any`s much anyway. Set[T] for any strongly-typed T is pretty-printed properly in the same way a literal would be written

Generated at Tue Dec 18 14:30:15 CET 2018 using JIRA 7.9.1#79001-sha1:60970b42586a2ec2760ed6cfe825b26961e62b9e.