From 55970f861daa6d94e661355735354d1cf3078dfa Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 5 Aug 2021 00:29:00 +0200 Subject: [PATCH] Add a "Classes" section to the docs/gettingstarted.md file, and edit a few lines. --- docs/gettingstarted.md | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/docs/gettingstarted.md b/docs/gettingstarted.md index ed9b651..af2c673 100644 --- a/docs/gettingstarted.md +++ b/docs/gettingstarted.md @@ -11,13 +11,13 @@ getHelloWorld: ~String => { return "Hello, World!" } ``` -The type (~String here) 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 `>>` and put the (optional) return type before the function's name: +To define a **named** (and mandatorily final) function, replace `=>` with `>>`: ``` -String getHelloWorld >> { +getHelloWorld: String >> { return "Hello, World!" } ``` @@ -60,22 +60,22 @@ addNumbers(a = 1, b = 2, c = 3, d = 4) # Call with names addNumbers(1, c = 3, b = 2, d = 4) ``` -Note that println is the only function that will get transpiled to its equivalent. +Note that print and println are the functions that will get transpiled to their equivalents. ## 3 - Types Types are *inferred*, which means that specifying types of variables or returned values is optional. 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. -Every variable has a static type by default; it is possible to make a **non-final** variable dynamic by adding the `dyn`/`dynamic` attribute: +Every variable has a static type by default; it is possible to make a **non-final** variable dynamic by adding `dyn`/`dynamic` to the attributes or making it the return type: ``` -dyn helloWorld = 0 +dyn helloWorld = 0 # helloWorld: dyn = 0 would also work helloWorld = "Hello, World!" ``` -The attributes mentioned above can also be used as a return type for functions/anonymous functions: +The attributes/return types mentioned above can also be used for functions/anonymous functions: ``` helloWorld: ~dynamic => { return 0 } -dyn helloWorld >> { return 0 } +dyn helloWorld >> { return 0 } # could be written as helloWorld: dyn >> { return 0 } ``` ## 4 - Comments @@ -83,5 +83,23 @@ You can add comments to your code; see the following examples showcasing the ava ``` # This is a simple comment // This is another comment -int # This is a compact comment, you can insert it pretty much anywhere # a = 1 +int ** This is a compact comment, you can insert it pretty much anywhere ** a = 1 +``` + +## 5 - Classes +A class can be made with the keyword, their name, optional constructors (`~()`) where you can add parameters and code that will run when the class is instantiated, and the class body where you can define methods, properties etc: +``` +class Program { + hello #= "Hello" + ~(str: String): () { + print(", $str!\n") + } + ~() { + print(hello) + } +} + +main >> { + Program("World") +} ``` \ No newline at end of file