- Defined with the let operator
- Immutable
let a = 1 // immutable
var b = 2 // mutable
- Defined with the var operator
- Mutiple variables may be defined at once using a comma.
var a = 1
var x = 1, y = 2, z = 3
a = a + 1
By default, types are infered by the value defined on the right hand site of a constant or variable declaration.
They may be explictly specified using a type annotation.
var a: Integer = 1
Byte 1b
Number 1, 1.1 alias for Float64
Integers 1i Int16, Int32, _Int64_, Int128
Floats 1f Float32, _Float64_
String "hello" UTF8 Encoded
Lists [ 1, 2, 3 ] List<Number>
Maps { a: 1, b: 2 } Dictionary<string, Number>
Tuples (1, 2, 3) Tuple<Number, Number, Number>
A protocal defines a set of operations that may be implemented by a Type.
Arithmetic<T> protocal {
* (this left: T, right:T) -> T;
/ (this left: T, right:T) -> T;
}
Any type may implement one or more protocals.
Unlike a class, implementations are defined in isolation.
Vector2 impl for Arithmetic<Vector2> {
* (right: Vector2) => Vector2(x * right.x, y * right.y)
/ (right: Vector2) => Vector2(x / right.x, y / right.y)
}
- Constants
- Shapes
a is (t: Type)
match x { 1 => ... 2 => ... (t: Type) => ... (a: T, b, T) => ... _ => ... }
pipes the result of the function into the next function as the first argument.
a |> b("extra") |> c
...
c(b(a(), "extra"))
Ranges are inclusive.
1..10
All enumerable objects may be looped through using a for operator.
for x in list {
log(x)
}
- automatically bound to $0 if an argument is not specified
for list {
log($0)
}
while condition {
}
let (a, b) = func()
Async by default.
Automatically yields thread when calling an async function and registers a continuation.
todo: overriding...
...