Mutable vs Immutable:
Values
You can name the results of expressions with the value keyword. Referencing a value doesn’t re-compute it.
Variable
var keyword is used to define a variable. Variables are immutable. Variables are similar to values, except we can re-assign them.
REPL (Read Evaluate Print Loop)
The REPL is a command line interpreter which is used to test our Scala code. It is simple to start a REPL session, just type Scala
on your operating system command line and write a simple equation and the output will be:
When we do not assign the result of our equation to any variable, the REPL automatically creates variable that start with the name res
. The output of variable is stored in res0
; the next one is stored in res1
, and so on.
REPL is also immutable, the reference example can be used as a reference.