打开Scala控制台(通过在终端中简单地运行scala
),可以调用一组命令,每个命令都以冒号:
开头。
通过在REPL中输入:help
(它本身就是其中之一),可以看到这些命令的列表。
scala> :help
All commands can be abbreviated, e.g. :he instead of :help.
:cp <path> add a jar or directory to the classpath
: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 reset execution and replay all previous commands
:reset 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> +enable/-disable flags, set compiler options
:silent disable/enable automatic printing of results
:type [-v] <expr> display the type of an expression without evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warnings from the most recent line which had any
在将这些行解释为Scala之前,这些命令是否是实际的Scala代码或可由REPL识别的任意字符串?
如果它们属于Scala世界,那么它们在语法上是什么?这些简单的方法遵循命名约定吗?
答案 0 :(得分:3)
它们是REPL语法的一部分,不属于Scala语法。
从REPL的角度来看,它们是语法命令。从Scala的角度来看,它们是语法错误。