The Scala REPL output is confusing

142 views
Skip to first unread message

Raphael Bosshard

unread,
Oct 31, 2016, 4:51:07 PM10/31/16
to scala-language
Hi all,

have you ever noticed how confusing the Scala REPL output it?

scala> def foo(in: String): Int = ???
foo
: (in: String)Int

I have learned what this "foo: (in: String)Int) is supposed to mean. But from a beginner's perspective I find it puzzling. Instead it should display something like this:

method created: foo(in: String): Int

Would someone support/guide me in fixing this?

Cheers,
Raphael



Oliver Ruebenacker

unread,
Oct 31, 2016, 4:55:16 PM10/31/16
to scala-l...@googlegroups.com

     Hello,

  That would add unnecessary clutter. Whoever entered the line knows they used def.

     Best, Oliver

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

Justin du coeur

unread,
Oct 31, 2016, 5:11:11 PM10/31/16
to scala-l...@googlegroups.com
(Note that this conversation started over on Gitter, and moved here.)

That's fair, but note that the output isn't legal Scala.  The "method created" bit I agree is arguable, but it really is kind of weird and confusing that there's no colon before "Int" in the output -- the output syntax seems strangely arbitrary.  Was there a specific reason for that, or is it just an old "seemed good enough at the time"?

I should note that I don't care passionately -- I don't use the REPL much myself.  But this seems like a pointless roadbump for new users, having the output be almost, but not quite, legal Scala.

And really, is "unnecessary clutter" (at least in small amounts) actually a problem in the REPL?  I would say that clarity is likely a higher priority than output conciseness...

Oliver Ruebenacker

unread,
Oct 31, 2016, 5:55:41 PM10/31/16
to scala-l...@googlegroups.com

     Hello,

  The line is just:

<name>: <type>

  With "(in: String)Int" being the type of the method.

  This resembles JNI method type notation, where the return type goes directly after the parens, too.

     Best, Oliver

Adriaan Moors

unread,
Oct 31, 2016, 6:46:14 PM10/31/16
to scala-l...@googlegroups.com
I agree the output would be nicer if we printed out the method definition in legal Scala. The current output is just printing the (strictly) internal representation of a method type.

I would be happy to help to improve this. I believe the logic for the output is here: https://github.com/scala/scala/blob/2.12.x/src/repl/scala/tools/nsc/interpreter/MemberHandlers.scala#L156

cheers
adriaan

To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

Naftoli Gugenheim

unread,
Oct 31, 2016, 9:58:23 PM10/31/16
to scala-l...@googlegroups.com

Could this be solved the easiest with scala.meta?

Adriaan Moors

unread,
Oct 31, 2016, 10:56:39 PM10/31/16
to scala-l...@googlegroups.com
I think everything needed is available from the compiler. Formatting this nicely (especially with colors) is a bit finicky, but I don't think meta would really help here.

Heather Miller

unread,
Nov 1, 2016, 5:47:46 AM11/1/16
to scala-l...@googlegroups.com
+1 to improving the REPL output such that it prints out the Scala method definition. I'd love to see this.
(I've always wondered why the REPL output wasn't friendlier!)



To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-language+unsubscribe@googlegroups.com.

Oliver Ruebenacker

unread,
Nov 1, 2016, 10:28:39 AM11/1/16
to scala-l...@googlegroups.com
So, what you want as REPL echo would be exactly what the user entered, except maybe with white space adjusted and return type added, right?

Heather Miller

unread,
Nov 1, 2016, 10:51:38 AM11/1/16
to scala-l...@googlegroups.com
Not exactly what was entered. Just the normal signature of what was entered. No body of the method, of course.

So for the example the OP started with, we print this now:
    foo: (in: String)Int

I understood that we'd print this instead: 
    def foo(in: String): Int

Oliver Ruebenacker

unread,
Nov 1, 2016, 11:14:41 AM11/1/16
to scala-l...@googlegroups.com
Right, not the body. Otherwise, essentially what the user entered, right?

Justin du coeur

unread,
Nov 1, 2016, 12:02:19 PM11/1/16
to scala-l...@googlegroups.com
Basically, yes.  Which is why a prefixing message of "Created" would be beneficial, but even without that it would be less mystifying than the current output...

Raphael Bosshard

unread,
Nov 1, 2016, 12:41:06 PM11/1/16
to scala-l...@googlegroups.com
Excellent. I'll give it a shot and come back if I need help. Do I need to create a PR for that?

--
You received this message because you are subscribed to a topic in the Google Groups "scala-language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-language/xiDCISJzbOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-language+unsubscribe@googlegroups.com.

Adriaan Moors

unread,
Nov 1, 2016, 12:58:05 PM11/1/16
to scala-l...@googlegroups.com
Yes, a PR will be needed for the CI to verify your changes. We have some docs (https://github.com/scala/scala/blob/2.12.x/README.md, http://scala-lang.org/contribute/hacker-guide.html) to help you get started, and are always happy to help on https://gitter.im/scala/contributors

To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "scala-language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-language/xiDCISJzbOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-languag...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.

Raphael Bosshard

unread,
Nov 3, 2016, 7:55:07 AM11/3/16
to scala-language
Hi all,

This is now https://issues.scala-lang.org/browse/SI-10023. We can discuss the specifics (i.e. how the new output should look like) there.

Thanks for all the help and directions!

Raphael

som-snytt

unread,
Nov 5, 2016, 2:31:57 AM11/5/16
to scala-language

I already responded to the cross-posting elsewhere -- that different users have different needs --

but Oliver's comment reminded me that the clever `//print` autocomplete mechanism is easy to overlook.

I'd like an output mode for REPL where it's basically doing what //print does. That is, echo what I typed with extra type info.

The only difference is that //print would not side-effect, but nobody does that anyway.

For example, when I enter f(17), show me the expanded expression.

scala> def f(i: Int)(implicit j: Int) = i + j
f: (i: Int)(implicit j: Int)Int

scala> implicit val x: Int = 42
x: Int = 42

scala> f(17) //print
   $line4.$read.$iw.$iw.f(17)($line5.$read.$iw.$iw.x) // : Int

scala> f(17)
res0: Int = 59

Jasper-M

unread,
Nov 7, 2016, 6:45:17 AM11/7/16
to scala-language
I don't really have a problem with the output of method types and such in the REPL. But might it be an idea to trim all the $wrapper stuff from the output of //print ?

Op zaterdag 5 november 2016 07:31:57 UTC+1 schreef som-snytt:
Reply all
Reply to author
Forward
0 new messages