2021-07-31 21:04:15 +02:00
## 1 - Variables
Variables defined using #= can't be changed (they are "final"), while the ones affected using the normal operator (=) can.
```
2021-07-31 21:30:58 +02:00
helloworld #= "Hello, World!"
2021-07-31 21:04:15 +02:00
```
## 2 - (Anonymous) Functions
You can make an anonymous functions using the following syntax:
```
getHelloWorld: ~String => {
2021-07-31 21:30:58 +02:00
return "Hello, World!"
2021-07-31 21:04:15 +02:00
}
```
2021-07-31 22:20:56 +02:00
The type (~String here) can be omitted, see [#3 ](#3---types ).
2021-07-31 21:04:15 +02:00
Note that you can make `getHelloWorld` final by replacing `=>` with `#=>` .
To define a **named** (and mandatorily final) function, replace `=>` with `>>` and put the (optional) return type before the function's name:
```
String getHelloWorld >> {
return "Hello, World!"
}
```
2021-07-31 22:20:56 +02:00
2021-07-31 21:04:15 +02:00
### 2.1 - Main
Main can be a variable named `main` that contains an anonymous function, a function named `main` or a function that has the `as_main` attribute:
```
main #=> {}
main >> {}
as_main helloWorld >> {}
```
2021-07-31 22:20:56 +02:00
### 2.2 - Function parameters
Parameters can be added to an anonymous function by specifying the types as follows:
```
addIntToString (int, String) => { a, b;
println(b + a)
}
```
Named functions can have parameters ** (with mandatory names)** like in this example:
```
addIntToString(a: Int, b: String) => {
println(b + a)
}
```
### 2.3 - Function calls
A function can be simply invoked like this if it has no parameters:
```
helloWorld()
```
If a function does have parameters, you can call it with arguments in the right order; if the function is not anonymous, it's also possible to call it by using the names of the corresponding parameters:
```
addNumbers(int a, int b, int c, int d) >> {
println(a + b + c + d)
}
2021-07-31 22:36:03 +02:00
addNumbers(1, 2, 3, 4) # Call without names
addNumbers(a = 1, b = 2, c = 3, d = 4) # Call with names
addNumbers(1, c = 3, b = 2, d = 4)
2021-07-31 22:20:56 +02:00
```
Note that println is the only function that will get transpiled to its equivalent.
2021-07-31 21:04:15 +02:00
## 3 - Types
Types are *inferred* , which means that specifying types of variables or returned values is optional.
2021-07-31 21:30:58 +02:00
< sup > Note: While primitives types (`String`, `int` , `double` , `boolean` , `float` ) will be transpiled to their equivalents for the target of the transpiler, this is not the case for other types.< sup >
2021-07-31 21:04:15 +02:00
Every variable has a static type by default; it is possible to make a **non-final** variable dynamic by adding the `dyn` /`dynamic` attribute:
```
dyn helloWorld = 0
2021-07-31 21:30:58 +02:00
helloWorld = "Hello, World!"
2021-07-31 21:04:15 +02:00
```
The attributes mentioned above can also be used as a return type for functions/anonymous functions:
```
2021-07-31 21:30:58 +02:00
helloWorld: ~dynamic => { return 0 }
dyn helloWorld >> { return 0 }
2021-07-31 22:20:56 +02:00
```
## 4 - Comments
You can add comments to your code; see the following examples showcasing the available syntaxes:
```
# This is a simple comment
// This is another comment
int # This is a compact comment, you can insert it pretty much anywhere # a = 1
2021-07-31 21:04:15 +02:00
```