Search code examples
scalaread-eval-print-loop

How to enter a multi-line command in the Scala REPL?


I would like to enter something like the following match instruction, but formatted across multiple lines. Is that possible in the Scala REPL?

myString match { case patt(a) => true case _ => false }

Solution

  • If you're just typing it in as-is, the REPL should detect the opening brace when you return, so that it won't try to parse and execute the code until it finds the closing brace.

    You could also use paste mode by typing :pa or :paste. This will allow you to enter as much as you want in any format (two blank lines will automatically quit from it). Then when finished entering in code, you can press Ctrl + D to evaluate.