Welcome to the idea of language v2 based around Kotlin and Rust!
Comments in this language use C-like syntax.
// One-liner
function(/* Insides */) // Description of it!
/*
Multiple lines!
*/Language uses rust-like declaring variables that means every variable is immutable by default. Also instead of let it is val like in kotlin.
Declaring variable:
val variable: i32 = 2Declaring mutable variable:
val mut variable: i32 = 2Declaring constant (only primitive values can be in constant):
const CONSTANT: i32 = 2Uses rust-like types
- Signed integers:
i8,i16,i32,i64,i128andisize - Unsigned integer:
u8,u16,u32,u64,u128andusize - Floating-point numbers:
f8,f16,f32,f64,f128andfsize - Characters:
char(to create character use''example:'a') - Boolean:
bool(trueorfalse)
Tuples have a Rust-like syntax. They are groups with multiple types of values inside and have a fixed size. Declaring a tuple:
val tuple: (fsize,u16,bool) = (1.0, 24, true)To access a tuple use array-like syntax. Accessing a tuple:
val tuple: (fsize,u16,bool) = (1.0, 24, true)
val float: fsize = tuple[0] //1.0
val positiveNumber: u16 = tuple[1] //24
val boolean: bool = tuple[3] //trueSupports also deconstructing syntax into multiple variables. Deconstracting tuple:
val tuple: (fsize,u16,bool) = (1.0, 24, true)
val (float: fsize, positiveNumber: u16, boolean: bool) = tupleArrays also use kotlin-like syntax. type[size], type can be anything, size has usize type.
Declaring array:
val array: char[5] = ['0','1','a','c','n'] //declares arrayGetting value from array:
val array: char[5] = ['0','1','a','c','n']
val letter: char = array[2] // 'a'Sets in this language have a math-like syntax. They are collection of elements of the same type and have dynamic size. They work like hashset in other languages. Delcaring set:
val set: char{} = {'a','b','c','d','e','f','g','h'}Adding new value to set:
val mut set: char{} = {'a','b','c','d','e','f','g','h'}
set.push('i')Removing value:
val mut set: char{} = {'a','b','c','d','e','f','g','h','i'}
set.remove('i')Maps in this language has js-like syntax. They work like HashMaps, having key-value pairs, keys are unique.
Declaring is done between {type:type}, first type is of key, second type is of value.
Declaring map:
val map: {char:i32} = {
'a': 2,
'b': 3,
'g': 3,
'o': 0
}Modifying/getting value from map has array-like syntax but instead of usize, you pass the key type. Modifying map:
val mut map: {char:i32} = {
'a': 2,
'b': 3,
'g': 3,
'o': 0
}
map['o'] = 10Getting value:
val map: {char:i32} = {
'a': 2,
'b': 3,
'g': 3,
'o': 0
}
val value: i32 = map['a'] //2Tables are similiar to maps but allows multiple values per key. The syntax for creating a table is the same as for maps, but with additional types specified inside the curly braces. Type {key:value,value}
Declaring table:
val table: {char:i32,bool} {
'a': 64, true
'b': 128, true
}Getting value from table:
val table: {char:i32,bool} {
'a': 64, false
'b': 128, true
}
val value: (i32,bool) = table['b'] // (128,true)List is similiar to array, but it can be resized. Declaring a list:
val list: [[char]] = [['a','a','g','f']]
Function syntax is similiar to kotlin functions, difference is replacement of fun with fn
Declaring a function:
fn function(x: i32): i32 = x^2 //short syntax
fn function(x: i32): i32 {
<- x^2 //instead of return there is <-
} //long syntax
Functions also support default values in arguments. Example default value:
fn function(x: i32 = 2): i32 = x^2 //4 by default :p
Language also supports lambdas, the lambda syntax is kotlin-like.
val lambda: () -> () = {}
val lambda: (i32) -> i32 = { x -> x^2 }
Supports kotlin-like package syntax. Instead of public there is pub, all declared stuff are private (file specific), also supports inter which means internal, it makes declared stuff only accessible inside the application/library.
Package example:
package MyPackage
pub fun publicated(x: i32): i32 = x^2
fun private(x: u32): u32 = x^2
inter fun internal(x: i32, y: i32): i32 = x^y
Importing a package: MyPackage file:
package MyPackage
pub fun publicated(x: i32): i32 = x^2
fun private(x: u32): u32 = x^2
inter fun internal(x: i32, y: i32): i32 = x^y
OtherFile:
import MyPackage //imports a package that you can use MyPackage@
import MyPackage.publicated //imports specific thing from package
import MyPackage.* //imports everything from package
Structures are used to create more complex data types from existing types. The language combines Rust's structure syntax with Kotlin's implementation of function syntax. (pub inside structures means that the value can be used outside the structure). Structure values also support default values.
Declaring structure:
import std
struct Person {
pub name: str@string = "Jane" //you dont need std@, you can just import `string` manually.
}
Implementing a function:
import std
struct Person {
pub name: str@string = "Jane"
}
Person.getName(): std@string = $.name
You can also implement a static value by putting * before Person
Implementing a static function:
import std
struct Person {
pub name: str@string = "Jane"
}
fn *Person.new(name: std@string): It = It(name) //It returns itself
This language has references with rust-like syntax, modifying mutable references is done using :=.
Use of references:
import std
fun referenceMutate(x: &mut i32) = x := x ^ 2
fun function() {
val mut x: i32 = 100
referenceMutate(&mut x)
std@println("{x}") //prints 10000
}
DSL is builder syntax that can be found in kotlin. Uses kotlin-like syntax. Type is Struct.(additional)->(return)
Declaring DSL function:
import std
struct Builder {
pub mut str: std@string,
pub mut integer: i32
}
fn builder(str: std@string, integer: i32, build: Builder.()->()) {
Builder(str,integer).apply(build)
}
Using a DSL function:
import std
struct Builder {
pub mut str: std@string,
pub mut integer: i32
}
fn Builder.callMe() = std@println("{$.str}: {$.integer}")
fn builder(str: std@string, integer: i32, build: Builder.()->()) {
Builder(str,integer).apply(build) //apply applies all modification and stuff done in builder
}
//...
builder("aaa", 100) {
$.str = "bbb"
$.integer = -100
$.callMe() //prints "bbb: -100"
} //this is lambda shorting that can be found in kotlin too.
Uses a DSL builder called init which is replacement for main function in kotlin/rust. This is done to give users way more stuff :p
A hello world example:
init {
println("Hello world!")
}
Using arguments:
init {
println("{$.args}") // prints list of arguments
}
- Addition:
+ - Subtraction:
- - Multiplication:
* - Power:
^ - Modulo:
% - Root:
^^ - Approximate:
~ - Equal:
== - Not equal:
!= - Greater than:
> - Lesser than:
< - Greater or equal than:
>= - Lesser or equal than:
<= - Division:
\ - Bitwise logic:
~,&,|,** - Bitwise shifts:
<<,>>, - Or:
|| - And:
&&