Welcome to the idea of language based around Kotlin and Rust!
Uses C-like comments
// One liner
function(/* Insides */) // description of it!
/*
multiple liner!
*/
There are many ways of writting variables in here. Every variable is by default immutable, requires you to specify mutability. Syntax of declaring variable is rust-like with optional let.
Example of immutable variable:
variable: i32 = 2
let variable: i32 = 2 //let is completely optional and not required, it will work exactly the same in example above
Example of mutable variable:
mut variable: i32 = 2 //you just put `mut` before name!
let mut variable: i32 = 2 // same here but after `let`
There also exists constant values which are strictly immutable, and only allow primitive values. They require to have const before name. It gets automatically inlined by compiler.
Example use:
const CONSTANT_VARIABLE: i32 = 2
Uses rust-like types
i8,i16,i32,i64,i128andisizesigned intigeru8,u16,u32,u64,u128andusizeunsigned integerf8,f16,f32,f64,f128andfsizefloatcharcharacter (to create character use''example:'a')boolboolean (trueorfalse)
Tuple syntax is also rust-like. They are groups with multiple types of values inside with fixed size and can be destructed. Example way of creating:
tuple: (fsize, u16, bool) = (1.0, 24, true)
Accessing value is different than in rust, instead of tuple.i (i is index/place of value in tuple) it uses array like syntax accessing.
Example way of accessing value:
value: fsize = tuple[0] //returns 1.0 of type fsize
// remember `tuple` variable is (1.0, 24, true)
You can also destruct the tuples by using different variable syntax which simply destructs the tuple into multiple variables. Example of destruction:
(float: fsize, number: u16, answer: bool) = tuple
float //returns 1.0 with type fsize
number //returns 24 with type u16
answer //returns true with type bool
Array syntax is instead kotlin-like. They are groups of same type and with fixed size. Example way of creating:
array: char[5] = ['h','e','l','l','o']
number inside char[5] defines fixed size of array, and char defines type of values in array.
You can access value inside array exactly the same way like you did in tuple!
Example of accessing value:
letter: char = array[3] //returns `l` with type char
Lambda are replacement for functions in this language, they use different syntax from other languages. To create lambda you use f(), f is used to different from tuples. By default they return nothing. They are executed like a function in C. They also use compacting for one line executions like in kotlin.
Example use of lambda in variable
lambda: f() = something()
They can be used in multiple line by using {}.
Example use:
lambda: f() = {
something()
something()
}
Lambda also can have return type which is said after f() like f(): i32.
Example use:
lambda: f(): i32 = 2 //will return `2`
You can also specify when the lambda will return if required, otherwise it will return last statement in block. Use <- for returning something instead of return in other languages.
Example use:
lambda: f(): i32 = {
2+2 //won't be returned
<- 4+4 //will return 8 and stop lambda here
5-5 //won't be reached
}
Lambdas also support arguments, arguments can be stated inside () like in other languages you would with functions.
Example use:
lambda: f(x: i32): i32 = x^2 //if executed `lambda(2)` will return `4`
//You can also specify which argument you pass value by using `lambda(x=2)`
Arguments also support default arguments, like you would see in kotlin. Example use:
lambda: f(x: i32 = 2): i32 = x^2 //If not passed anything by doing `lambda()` it will return 4, if did for example `lambda(6)` it will return 36.