summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorGeoff Liu <cangming.liu@gmail.com>2016-08-02 14:02:23 -0400
committerGitHub <noreply@github.com>2016-08-02 14:02:23 -0400
commit3f5106a323be07b55f4140e31db8778640396d09 (patch)
treea7bb0f1d33169983c0b266c4203a9e8afdc684f7 /scala.html.markdown
parentb7bfade6070381d0d4c506b19947adff4dff8c65 (diff)
parentf1b64fb6a67bf7fa5020a7effd1ace4edbb0a4b0 (diff)
Merge pull request #1782 from doub1ejack/scala-en-repl
[scala/en] Added REPL basics to help people experiment as they learn.
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown60
1 files changed, 50 insertions, 10 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
index 7f5f0ec3..5e3ece2d 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -12,22 +12,62 @@ Scala - the scalable language
```scala
+/////////////////////////////////////////////////
+// 0. Basics
+/////////////////////////////////////////////////
/*
- Set yourself up:
+ Setup Scala:
1) Download Scala - http://www.scala-lang.org/downloads
2) Unzip/untar to your favourite location and put the bin subdir in your `PATH` environment variable
- 3) Start a Scala REPL by running `scala`. You should see the prompt:
-
- scala>
-
- This is the so called REPL (Read-Eval-Print Loop). You may type any Scala
- expression, and the result will be printed. We will explain what Scala files
- look like further into this tutorial, but for now, let's start with some
- basics.
-
*/
+/*
+ Try the REPL
+
+ Scala has a tool called the REPL (Read-Eval-Print Loop) that is anologus to
+ commandline interpreters in many other languages. You may type any Scala
+ expression, and the result will be evaluated and printed.
+
+ The REPL is a very handy tool to test and verify code. Use it as you read
+ this tutorial to quickly explore concepts on your own.
+*/
+
+// Start a Scala REPL by running `scala`. You should see the prompt:
+$ scala
+scala>
+
+// By default each expression you type is saved as a new numbered value
+scala> 2 + 2
+res0: Int = 4
+
+// Default values can be reused. Note the value type displayed in the result..
+scala> res0 + 2
+res1: Int = 6
+
+// Scala is a strongly typed language. You can use the REPL to check the type
+// without evaluating an expression.
+scala> :type (true, 2.0)
+(Boolean, Double)
+
+// REPL sessions can be saved
+scala> :save /sites/repl-test.scala
+
+// Files can be loaded into the REPL
+scala> :load /sites/repl-test.scala
+Loading /sites/repl-test.scala...
+res2: Int = 4
+res3: Int = 6
+
+// You can search your recent history
+scala> :h?
+1 2 + 2
+2 res0 + 2
+3 :save /sites/repl-test.scala
+4 :load /sites/repl-test.scala
+5 :h?
+
+// Now that you know how to play, let's learn a little scala...
/////////////////////////////////////////////////
// 1. Basics