Variables
You can declare and assign value to variables with the following syntax:
# Assign variables:
first_name = "John"
last_name = "Doe"
age = 42
driver_license_type = 'A'
# Print values:
p first_name # => "John"
p last_name # => "Doe"
p age # => 42
p driver_license_type # => 'A'
The types of the variables are inferred by the compiler:
first_name = "John"
last_name = "Doe"
age = 42
driver_license_type = 'A'
# Print types:
p typeof(first_name) # => String
p typeof(last_name) # => String
p typeof(age) # => Int32
p typeof(driver_license_type) # => Char
It's possible to be explicit about types:
## Type declaration and assignment:
first_name : String = "John"
## Type declaration:
last_name : String
## Assignment
last_name = "Doe"
p first_name # => "John"
p last_name # => "Doe"
We can use the multiple assignment syntax to declare more than one variable in one statement or to reassign values:
x, y = 20, 30
p x # => 20
p y # => 30
x, y = y, x
p x # => 30
p y # => 20
It's also possible to have multiple statements on the same line by using a semicolon in between statements:
first_name = "John"; last_name = "Doe";