简体   繁体   English

如何在Scala REPL中输入多行命令

[英]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? 这可能在Scala REPL中吗?

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

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. 如果你只是按原样键入它,REPL应该在你返回时检测左括号,这样它就不会尝试解析并执行代码,直到它找到右括号。

You could also use paste mode by typing :pa or :paste . 您还可以通过键入以下内容来使用粘贴模式:pa: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. 然后在完成输入代码后,您可以按Ctrl + D进行评估。

One way to enter into multi-line mode in the Scala REPL is to hit enter right after the opening curly brace "{", then hit enter after each line until the last closing curly brace has been entered "}". 在Scala REPL中进入多行模式的一种方法是在打开大括号“{”后立即按Enter键,然后在每行之后按Enter键,直到输入最后一个结束大括号“}”。 Hitting enter after it will exit the multi-line mode 在退出多行模式后按Enter键

myScript match { <enter> //enter multi-line mode
  | case scriptStart(a) => true <enter>
  | case _ => false <enter>
  |} <enter> //exit multi-line mode

When cascading transformations, it is as simple as ending each line with a dot. 级联转换时,就像用一个点结束每一行一样简单。 For example: 例如:

val wordcount = sc.
  textFile("MYFILE.txt").
  flatMap( x => x.split(" ") ).
  map( w => (w,1) ).
  reduceByKey( (a,b) => a+b )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM