码迷,mamicode.com
首页 > 其他好文 > 详细

Scala介绍

时间:2020-01-22 11:09:22      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:bbr   hotspot   get   oss   setting   play   summary   line   shel   

日期: 2020-01-22

1.概述和安装

Scala是“可扩展语言”的缩写(SCAlable Language),于2003创建,为JVM平台上的函数式编程以及面向对象编程提供一个高性能开发环境。所以,Scala要求使用java运行时库。并且scala是编译型静态类型语言。

在mac环境使用HomeBrew来安装scala比较方便(需要前置安装Java),直接输入命令:

$ java -version
$ brew install scala

 直接输入scala就可以启动scala REPL来交互编程。

  1. scala REPL提供了一个帮助系统,使用:help命令可以启动。
  2. 当命令返回值时,REPL会把它赋给一个新的常量变量,这些“res”变量会顺序编号,并且可以在后边命令中使用(例如 2*res2)
  3. 使用 :load 命令可以加载外部的scala代码并执行。
  4. 可以使用 :paste -raw 命令,并按回车键之后,粘贴外部的scala代码在REPL中执行。在mac terminal中尝试过无法退出粘贴模式不建议使用这种方法,使用load文件的方式更好。
技术图片
 1 $ scala
 2 Welcome to Scala 2.13.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_172).
 3 Type in expressions for evaluation. Or try :help.
 4 
 5 scala>
 6 
 7 scala> println("Hello World!")
 8 Hello World!
 9 
10 scala> 5*7
11 res2: Int = 35
12 
13 scala> 2*res2
14 res3: Int = 70
15 
16 scala> :help
17 All commands can be abbreviated, e.g., :he instead of :help.
18 :completions <string>    output completions for the given string
19 :edit <id>|<line>        edit history
20 :help [command]          print this summary or command-specific help
21 :history [num]           show the history (optional num is commands to show)
22 :h? <string>             search the history
23 :imports [name name ...] show import history, identifying sources of names
24 :implicits [-v]          show the implicits in scope
25 :javap <path|class>      disassemble a file or class name
26 :line <id>|<line>        place line(s) at the end of history
27 :load <path>             interpret lines in a file
28 :paste [-raw] [path]     enter paste mode or paste a file
29 :power                   enable power user mode
30 :quit                    exit the interpreter
31 :replay [options]        reset the repl and replay all previous commands
32 :require <path>          add a jar to the classpath
33 :reset [options]         reset the repl to its initial state, forgetting all session entries
34 :save <path>             save replayable session to a file
35 :sh <command line>       run a shell command (result is implicitly => List[String])
36 :settings <options>      update compiler options, if possible; see reset
37 :silent                  disable/enable automatic printing of results
38 :type [-v] <expr>        display the type of an expression without evaluating it
39 :kind [-v] <type>        display the kind of a type. see also :help kind
40 :warnings                show the suppressed warnings from the most recent line which had any
41 
42 scala> "Hello World!"
43 res4: String = Hello World!
44 
45 scala> (22.5 * 9/5) + 32
46 res5: Double = 72.5
47 
48 scala> res5/2
49 res6: Double = 36.25
50 
51 scala> :load /Users/natty/Develop/Learning/scala/LearningScala/Hello.scala
52 args: Array[String] = Array()
53 Loading /Users/natty/Develop/Learning/scala/LearningScala/Hello.scala...
54 Hello file world!
55 
56 scala> :paste -raw
57 // Entering paste mode (ctrl-D to finish)
58 
59 println("Hello file world!")
View Code

 

Scala介绍

标签:bbr   hotspot   get   oss   setting   play   summary   line   shel   

原文地址:https://www.cnblogs.com/natty-sky/p/12228007.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!