Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Comments:
- // This is a single line
- /*
- These
- are multiple
- lines
- /* can be nested */
- */
- /**
- ### This is a doc comment
- *you can use markdown in here*
- */
- Variables:
- int a = 0 // type: int
- const int b = 0 // type: int
- const c = 0 // type: int, constant (inferred)
- var d = 0 // type: int, (inferred)
- e = 0 // type: any
- Functions:
- // a is type any, b is type int, function returns any
- def foo a, int b
- // code here
- return a // explicit return
- a // implicit return
- // a is type any, b is type int?, function returns int
- def foo a, int? b -> int
- // code here
- return int! a // has to be cast to int
- // a is type any?, b is type (int -> int?), function returns int
- def foo a?, (int -> int?) b -> int
- return int! b()
- Varargs:
- def foo int a...
- print(a(1)) if a:size() > 0
- Casting:
- int? a = null
- int b = int! a // cast to type
- int c = !! a // autocast
- Type checking:
- var a = 10
- var tpe = type a // tpe is of type (type<int>)
- if a is type int // runtime type checking
- // code here
- Lambdas:
- a = \a, b, c -> bar(a, b, c)
- // or multiple lines
- a = \a, b, c ->
- bar(a, b, c)
- baz()
- // no parameters
- a = \-> bar()
- // shorter
- a = do bar()
- if, else if:
- if a == b
- // code here
- else if a == c
- // and here
- else
- // and there
- foo = bar if a == b // one line
- If statemenets can return values:
- bar = if foo
- // code here
- boo() // implicit return
- else
- doo() // implicit return
- Or shorter:
- bar = boo() if foo else doo()
- Arrays:
- array = {1, 2, 3, 4} // type: [4 int]
- [4 float] array = {1, 2, 3, 4} // type: [4 float]
- Lists and maps:
- var list = [1, 2, 3, 4] // type: list<int>
- list<float> list = [1, 2, 3, 4] // type: list<float>
- var map = ["foo" = 0] // type: map<string, int>
- map<any, float> map = ["foo" = 1] // type: map<any, float>
- map2 = ["foo" = 0] // type: any
- Function calls:
- Normal call:
- foo()
- foo(a, b, c)
- Call with...
- foo "string" // string literal
- foo 1242 // number literal
- foo \a, b -> b // lambda
- foo do
- goo()
- boo() // lambda
- foo {1, 2, 3} // array
- foo [1, 2, 3] // list
- foo {"a" = b} // map
- Structs:
- struct foo
- int a = 20
- var c = 50
- [5 int] d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement