Add a "Classes" section to the docs/gettingstarted.md file, and edit a few lines.
This commit is contained in:
parent
328a073d50
commit
55970f861d
|
@ -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.
|
||||
|
||||
<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:
|
||||
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")
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue