Variables
There are two type of variables: val and var.
val are immutable, both in the binding & the underlying value, so they can't be modified
in anyway.
CODE_PLAYGROUND
val name = "John"
val lastname = "Doe"
The underlying value is also immutable, so attempting to indirectly modify them will also fail:
CODE_PLAYGROUND
val pet = Dog("Nala")
pet.name = "Rufus" // This is an error
pet.add_years(1) // If a method changes data, it's also an error
var are mutable. The binding & the value is mutable.
CODE_PLAYGROUND
var pet = "Nala"
pet = "Rufus" // OK
Type annotations
Types are marked with a colon, then the type:
CODE_PLAYGROUND
val name: String = "Pablo"
val age: u64 = 32
val married: bool = false
However, variables can omit a type annotation just fine.
Types
Nara has primitive types and reference types. Primitives are:
u8, i32, u32, f32, i64, u64, f64, bool.
Reference types live on the heap. The most fundamental one is
String.
More info about them in their article.