summaryrefslogtreecommitdiffhomepage
path: root/scala.html.markdown
diff options
context:
space:
mode:
authorGeorge Petrov <petrovg@gmail.com>2013-07-28 20:52:32 +0100
committerGeorge Petrov <petrovg@gmail.com>2013-07-28 20:52:32 +0100
commit2e7c3ba085da91a198f7b339d57bdf1fd8c8b49c (patch)
tree10b99343124e829383dd09b5aa98b3d589c7848c /scala.html.markdown
parenta7fe2983ccbe5de97d5f21ee1ee0e2aac1e0be16 (diff)
Starting a Scala one
Diffstat (limited to 'scala.html.markdown')
-rw-r--r--scala.html.markdown53
1 files changed, 53 insertions, 0 deletions
diff --git a/scala.html.markdown b/scala.html.markdown
new file mode 100644
index 00000000..f087881a
--- /dev/null
+++ b/scala.html.markdown
@@ -0,0 +1,53 @@
+/*
+ Set yourself up:
+
+ 1) Download Scala - http://www.scala-lang.org/downloads
+ 2) unzip/untar in your favourite location and put the bin subdir on the path
+ 3) Start a scala REPL by typing scala. You should see the prompt:
+
+ scala>
+
+ This is the so called REPL. You can run commands in the REPL. Let do just that:
+*/
+
+println(10) // prints the integer 10
+
+println("Boo!") // printlns the string Boo!
+
+
+// Evaluating a command gives you the type and value of the result
+
+1 + 7
+
+/* The above line results in:
+
+ scala> 1 + 7
+ res29: Int = 8
+
+ This means the result of evaluating 1 + 7 is an object of type Int with a value of 8
+
+ 1+7 will give you the same result
+*/
+
+
+// Everything is an object, including a function type these in the repl:
+
+7 // results in res30: Int = 7 (res30 is just a generated var name for the result)
+
+// The next line gives you a function that takes an Int and returns it squared
+(x:Int) => x * x
+
+// You can assign this function to an identifier, like this:
+val sq = (x:Int) => x * x
+
+/* The above says this
+
+ sq: Int => Int = <function1>
+
+ Which means that this time we gave an explicit name to the value - sq is a function that take an Int and returns Int.
+
+ sq can be executed as follows:
+*/
+
+sq(10) // Gives you this: res33: Int = 100. The result is the Int with a value 100
+