Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Scala 3 REPL commands #131

Closed
alvinj opened this issue Jul 31, 2020 · 9 comments
Closed

Scala 3 REPL commands #131

alvinj opened this issue Jul 31, 2020 · 9 comments

Comments

@alvinj
Copy link

alvinj commented Jul 31, 2020

Background

Per our discussion, the Scala 2.13 REPL has these commands:

scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:completions <string>    output completions for the given string
:edit <id>|<line>        edit history
:help [command]          print this summary or command-specific help
:history [num]           show the history (optional num is commands to show)
:h? <string>             search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v]          show the implicits in scope
:javap <path|class>      disassemble a file or class name
:line <id>|<line>        place line(s) at the end of history
:load <path>             interpret lines in a file
:paste [-raw] [path]     enter paste mode or paste a file
:power                   enable power user mode
:quit                    exit the interpreter
:replay [options]        reset the repl and replay all previous commands
:require <path>          add a jar to the classpath
:reset [options]         reset the repl to its initial state, forgetting all session entries
:save <path>             save replayable session to a file
:sh <command line>       run a shell command (result is implicitly => List[String])
:settings <options>      update compiler options, if possible; see reset
:silent                  disable/enable automatic printing of results
:type [-v] <expr>        display the type of an expression without evaluating it
:kind [-v] <type>        display the kind of a type. see also :help kind
:warnings                show the suppressed warnings from the most recent line which had any

The scala command also has these command-line options:

Options to scala which reach the Java runtime:

 -Dname=prop  passed directly to Java to set system properties
 -J<arg>      -J is stripped and <arg> passed to Java as-is
 -nobootcp    do not put the Scala jars on the boot classpath (slower)

Other startup options:

 -i <file>    preload <file> before starting the REPL
 -I <file>    preload <file>, enforcing line-by-line interpretation
 -e <string>  execute <string> as if entered in the REPL
 -save        save the compiled script in a jar for future use

If the runner does not correctly guess how to run the target:

 -howtorun    what to run <script|object|jar|guess> (default: guess)

The current Dotty REPL (dotr) has these commands:

scala> :help                                                                                                         
The REPL has several commands available:

:help                    print this summary
:load <path>             interpret lines in a file
:quit                    exit the interpreter
:type <expression>       evaluate the type of the given expression
:doc <expression>        print the documentation for the given expresssion
:imports                 show import history
:reset                   reset the repl to its initial state, forgetting all session entries

I can’t determine if dotr has any command-line options.

Issue(s)

I think part of the discussion was going to be, which of these commands should be enabled in the Scala 3 REPL? I also added the command-line options here, though that might be a separate issue.

(Also, if I haven’t put this issue in the correct place, just point me to the proper location. Thanks.)

@smarter
Copy link
Member

smarter commented Aug 8, 2020

I can’t determine if dotr has any command-line options.

You can use -help to get a help text for dotr and dotc.

I think part of the discussion was going to be, which of these commands should be enabled in the Scala 3 REPL?

Except for :power which is very specific to Scala 2, we welcome contributions which implement any of the commands from the Scala 2 REPL. (I'm also not sure if :paste is needed given that JLine 3 seems to handle multi-line pasting fine).

@SethTisue
Copy link

I agree that :paste is not needed. JLine 3 handles multiline paste just fine, and if your goal with :paste is to enter multiple constructs and have them compiled together, JLine 3 allows option-return to start a new line without terminating input.

@som-snytt
Copy link

paste and load offer different semantics.

➜  ~ cat stuff.scala
// useful stuff
import collection.{mutable, immutable}
➜  ~ scala
Welcome to Scala 2.13.6 (OpenJDK 64-Bit Server VM, Java 16.0.1).
Type in expressions for evaluation. Or try :help.

scala> :paste stuff.scala
Pasting file stuff.scala...
import collection.{mutable, immutable}

scala> :load stuff.scala
val args: Array[String] = Array()
Loading stuff.scala...
import collection.{mutable, immutable}

@alvinj
Copy link
Author

alvinj commented Jun 17, 2021

FWIW, in regards to Scala 3, I just copied-and-pasted those commands from the Scala 2 REPL without much thought as to what was really needed. I was writing the Command Line chapter for the Scala Cookbook (for Scala 3) at the time (and we also had a brief Zoom call where we discussed this), and I noticed that the number of commands that were in the REPL had been greatly reduced.

(And wow, I didn’t know you could :paste a file like that.)

@Jasper-M
Copy link

Jasper-M commented Jun 18, 2021

If you don't have :paste how do you do :paste -raw?

JLine 3 allows option-return to start a new line without terminating input

That doesn't seem to work for me by default. Also, I thought the generally accepted combination for "newline without commit" is shift-return, which should work the same on all kinds of keyboards.

@Jasper-M
Copy link

Jasper-M commented Jun 18, 2021

Scala 2 REPL also has some "hidden" functions like this which would be nice to have as well.

scala> for(i <- List(1,2,3)) yield i + 1 //print<TAB>
scala.`package`.List.apply[Int](1, 2, 3).map[Int](((i: Int) => i.+(1))) // : List[Int]

Perhaps in a more official capacity. E.g.

scala> :desugar for(i <- List(1,2,3)) yield i + 1
scala.`package`.List.apply[Int](1, 2, 3).map[Int](((i: Int) => i.+(1))) // : List[Int]

@som-snytt
Copy link

Worth noting that scala 2 REPL detects package which becomes automatically raw not wrapped. That was a paulp idea.

I don't know offhand if there is a compelling use case for REPL emitting into the empty package, although that is what empty package is for, just trying stuff out. Raw paste enables that, since you can't name empty package.

@SethTisue
Copy link

Note that although Scala 3 has :reset, it doesn't support passing settings, which is a useful Scala 2 behavior.

@SethTisue
Copy link

Note that although Scala 3 has :reset, it doesn't support passing settings, which is a useful Scala 2 behavior

Dale has now implemented this: scala/scala3#14139 (also Chris's scala/scala3#14521)

@lampepfl lampepfl locked and limited conversation to collaborators Jun 5, 2023
@ckipp01 ckipp01 converted this issue into a discussion Jun 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants