Change the syntax for anonymous functions in docs/gettingstarted.md

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-04-08 10:53:19 +02:00
parent 00a8fbaa83
commit 1d3046892f
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 4 additions and 6 deletions

View File

@ -7,15 +7,13 @@ helloworld #= "Hello, World!"
## 2 - (Anonymous) Functions ## 2 - (Anonymous) Functions
You can make an anonymous functions using the following syntax: You can make an anonymous functions using the following syntax:
``` ```
getHelloWorld: ~String => { getHelloWorld: ~String #= {
return "Hello, World!" return "Hello, World!"
} }
``` ```
The type (`~String` here, which basically means "an anonymous function that returns a String") can be omitted, see [#3](#3---types). The type (`~String` here, which basically means "an anonymous function that returns a String") can be omitted, see [#3](#3---types).
Note that you can make `getHelloWorld` final by replacing `=>` with `#=>`. To define a **named** (and mandatorily final) function, replace `#=` with `>>`:
To define a **named** (and mandatorily final) function, replace `=>` with `>>`:
``` ```
getHelloWorld: String >> { getHelloWorld: String >> {
return "Hello, World!" return "Hello, World!"
@ -25,7 +23,7 @@ getHelloWorld: String >> {
### 2.1 - Main ### 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 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 #= {}
main >> {} main >> {}
as_main helloWorld >> {} as_main helloWorld >> {}
``` ```
@ -33,7 +31,7 @@ as_main helloWorld >> {}
### 2.2 - Function parameters ### 2.2 - Function parameters
Parameters can be added to an anonymous function by specifying the types as follows: Parameters can be added to an anonymous function by specifying the types as follows:
``` ```
addIntToString (int, String) => { a, b; addIntToString: (int, String)~ #= { a, b;
print_line(b + a) print_line(b + a)
} }
``` ```