46 lines
1.5 KiB
Markdown
46 lines
1.5 KiB
Markdown
## 1 - Variables
|
|
Variables defined using #= can't be changed (they are "final"), while the ones affected using the normal operator (=) can.
|
|
```
|
|
helloworld #= "Hello, World!"
|
|
```
|
|
|
|
## 2 - (Anonymous) Functions
|
|
You can make an anonymous functions using the following syntax:
|
|
```
|
|
getHelloWorld: ~String => {
|
|
return "Hello, World!"
|
|
}
|
|
```
|
|
<sub>`~String` can be omitted, see [#3](#3---types).</sub>
|
|
|
|
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!"
|
|
}
|
|
```
|
|
### 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 >> {}
|
|
```
|
|
|
|
## 3 - Types
|
|
Types are *inferred*, which means that specifying types of variables or returned values is optional.
|
|
|
|
<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>
|
|
|
|
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
|
|
helloWorld = "Hello, World!"
|
|
```
|
|
The attributes mentioned above can also be used as a return type for functions/anonymous functions:
|
|
```
|
|
helloWorld: ~dynamic => { return 0 }
|
|
dyn helloWorld >> { return 0 }
|
|
``` |