Variables
A variable number of variables
A variable is a memory storage used to store a value or a reference. SMLL has two kinds of variable declaration:
Val
val number = 10
val name = "Jake"
val answer = number * 2
val (op, left, right) = binop (* Value destructuring using val *)
The keyword val binds a name, on the left hand side of the expression to a value on the right hand side of the expression. This is similar to how variables work in every other programming language. The val keyword also support value destructuring for struct values.
Let
let
number = 10
name = "Jake"
answer = number * 2
in answer
The let keyword binds a list of names to their corresponding expressions and finally returns a result at the end. This is useful of such cases where code readability is sometimes needed:
From
val one = 1
val two = 2
val three = 3
val six = one + two + three
To
val six =
let
one = 1
two = 2
three = 3
in one + two + three
Last updated