2.scala编程思想笔记——运行Scala
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/50444091
源码下载连接请见第一篇笔记。
Scala解释器也成为REPL(Read-Evaluate-Print-Loop,读取-计算-打印-循环)
按照上节配置环境后,输入scala就进入了REPL。如下:
[root@localhostexamples]#scala
Welcome to Scala version 2.11.7 (OpenJDK64-Bit Server VM, Java 1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
1. 算术运算如下:
scala> 43*11.3
res0: Double = 485.90000000000003
其中res0表示计算结果命名
Double表示双精度浮点数
2. 帮助
输入Help可以获得更多信息如下:
scala> :help
All commands can be abbreviated, e.g., :heinstead of :help.
:edit <id>|<line> edit history
:help [command] print this summary orcommand-specific help
:history [num] show the history (optional num iscommands to show)
:h? <string> search the history
:imports [name name ...] show importhistory, 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 previouscommands
: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 isimplicitly => List[String])
:settings <options> update compiler options, if possible; seereset
:silent disable/enable automaticprinting of results
:type [-v] <expr> display the type of an expressionwithout evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warningsfrom the most recent line which had any
3. 注释:
注释是说明性的文本
使用//开头的注释,直到当前行末尾
多行注释用/*开头 */ 结束。
和C语言基本一致。