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 #10024

Closed
scabug opened this issue Nov 3, 2016 · 15 comments · Fixed by scala/scala#8319
Closed

Improve REPL display #10024

scabug opened this issue Nov 3, 2016 · 15 comments · Fixed by scala/scala#8319

Comments

@scabug
Copy link

scabug commented Nov 3, 2016

The current REPL output for definitions is very confusing because it is almost, but not quite valid Scala and also inconsistent.

Some examples:

scala> case class Foo()
defined class Foo
scala> trait Bar
defined trait Bar
scala> type Qux = Nothing
defined type alias Qux
scala> val a = 1
a: Int = 1
scala> var b = 1
b: Int = 1

The Scala REPL's response should be more consistent reporting about definitions.
Possible solutions

  • no output in the success case (as does the Python REPL)
  • display the type definition (as it is currently the case but without "defined" )
  • display the type definition as valid Scala
  • ...
@scabug
Copy link
Author

scabug commented Nov 3, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10024?orig=1
Reporter: Raphael Bosshard (esarbe)
Blocks #7960, #10023

@scabug
Copy link
Author

scabug commented Nov 3, 2016

@som-snytt said:
There's a PR underway for pretty-printing. Also consider output such as

scala> val (x, y) = (42, 17)
x: Int = 42
y: Int = 17

Customizing output is not amenable to piece-meal tweaks.

@scabug
Copy link
Author

scabug commented Nov 3, 2016

Raphael Bosshard (esarbe) said:
What's the pretty-printing PR's number?

@scabug
Copy link
Author

scabug commented Nov 3, 2016

@dwijnand said:
[~esarbe]: scala/scala#5222

@eed3si9n
Copy link
Member

eed3si9n commented Feb 6, 2018

This and related REPL display issues might be good first issue if they were defined clearly on what are expected at the end.

For example, this issue says "no output in the success case (as does the Python REPL)" as possible solution while #7960 says it would be better to include val or val:

scala> var x = 5
var x: Int = 5

@SethTisue
Copy link
Member

no output in the success case (as does the Python REPL)

I agree with #7960. I think it's valuable to show the types, and it's valuable to show the computed value, too:

scala> val x = 2 + 2
x: Int = 4

@SethTisue
Copy link
Member

closed #7960 and #10023, consolidating here.

@SethTisue
Copy link
Member

note that anyone doing nontrivial REPL work should target 2.13, since the REPL code changed around between 2.12 and 2.13 so merging changes forward is extra work we'd rather not do.

@jonathanfrawley
Copy link

Hi,

I'm willing to pick this up, what exactly is the desired outcome? Do we want nothing in the case of a type definition, and to keep var and val definitions the same? Something like this:

scala> case class Foo()
scala> val (x, y) = (42, 17)
x: Int = 42
y: Int = 17

@SethTisue
Copy link
Member

I'm willing to pick this up

awesome!

what exactly is the desired outcome

this is all open-ended and open to debate. these tickets were opened by interested individuals with opinions, they aren't the outcome of any process.

if something is easy to tweak you might just go ahead and we can bikeshed it after, if something looks like bunch of work then you might check first whether people think it's a good idea

re: "nothing in the case of a type definition", sounds good to me

re: "keep var and val definitions the same", #7960 (which is now consolidated here) proposes adding val or var to bring it closer to being legal Scala that's printed

@jonathanfrawley
Copy link

Cool, I'll have a go at changing it to what I suggested above and come back here for feedback once it is ready or I reach a stumbling block.

@psilospore
Copy link

@df3n5 are you still planning on working on this? I was wondering if I could make an attempt.

@jonathanfrawley
Copy link

@psilospore No, I have no time for contributions at the moment. Good luck with it!

@SethTisue
Copy link
Member

also in this area: #11416

@bishabosha
Copy link
Member

bishabosha commented Aug 6, 2019

I'm currently working on this now, with the following choices:

val/var

scala> lazy val x = ""
lazy val x: String = <lazy>

scala> val (a, b) = (true, false)
val a: Boolean = true
val b: Boolean = false

scala> var mut = 0
var mut: Int = 0

scala> mut = 1
// mutated mut

def/macro

scala> def foo = ""
def foo: String = <method>

scala> def foo[T: ClassTag, A: ClassTag](x: T): String = x.toString
def foo[T, A](x: T)(implicit evidence$1: ClassTag[T], evidence$2: ClassTag[A]): String = <method>

scala> def m(x: => Int): Int = macro ???
// defined term macro m(x: => Int): Int

definitions

scala> object A
// defined object A

scala> trait B
// defined trait B

scala> class C
// defined class C

scala> type D = Unit
// defined type alias D

@eed3si9n eed3si9n changed the title REPL output should be less confusing Improve REPL display Aug 6, 2019
lrytz added a commit to scala/scala that referenced this issue Sep 26, 2019
@SethTisue SethTisue removed this from the Backlog milestone Sep 26, 2019
@SethTisue SethTisue added this to the 2.13.2 milestone Sep 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants