more docs
This commit is contained in:
parent
9a9f712cec
commit
ff03f3066d
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,4 +12,4 @@ xcuserdata
|
||||
#So we don't accidentally commit our private keys
|
||||
*.gpg
|
||||
.gigaide
|
||||
.kotlin
|
||||
/kotlin-js-store/yarn.lock
|
||||
|
@ -98,17 +98,43 @@ There is a set of assigning operations: `+=`, `-=`, `*=`, `/=` and even `%=`.
|
||||
|
||||
Notice the parentheses here: the assignment has low priority!
|
||||
|
||||
## Expression details
|
||||
## Math
|
||||
|
||||
It is rather simple, like everywhere else:
|
||||
|
||||
val x = 2.0
|
||||
//
|
||||
sin(x * π/4) / 2.0
|
||||
>>> 0.5
|
||||
|
||||
See [math](math.md) for more on it. Notice using Greek as identifier, all languages are allowed.
|
||||
|
||||
Logical operation could be used the same
|
||||
|
||||
val x = 10
|
||||
++x >= 11
|
||||
>>> true
|
||||
|
||||
## Supported operators
|
||||
|
||||
| op | ass | args |
|
||||
|:--------:|-----|-------------------|
|
||||
| + | += | Int or Real |
|
||||
| - | -= | Int or Real |
|
||||
| * | *= | Int or Real |
|
||||
| / | /= | Int or Real |
|
||||
| % | %= | Int or Real |
|
||||
| && | | Bool |
|
||||
| \|\| | | Bool |
|
||||
| !x | | Bool |
|
||||
| < | | String, Int, Real |
|
||||
| <= | | String, Int, Real |
|
||||
| >= | | String, Int, Real |
|
||||
| > | | String, Int, Real |
|
||||
| == | | Any |
|
||||
| != | | Any |
|
||||
| ++a, a++ | | Int |
|
||||
| --a, a-- | | Int |
|
||||
|
||||
# Variables
|
||||
|
||||
Much like in kotlin, there are _variables_:
|
||||
@ -137,7 +163,8 @@ Same as in kotlin:
|
||||
|
||||
val HalfPi = π / 2
|
||||
|
||||
Note using greek characters in identifiers! All letters allowed, but remember who might try to read your script, most likely will know some English, the rest is the pure uncertainty.
|
||||
Note using greek characters in identifiers! All letters allowed, but remember who might try to read your script, most
|
||||
likely will know some English, the rest is the pure uncertainty.
|
||||
|
||||
# Defining functions
|
||||
|
||||
@ -161,7 +188,9 @@ There are default parameters in Ling:
|
||||
else
|
||||
"more"
|
||||
}
|
||||
>>> Callable@...
|
||||
assert( "do: more" == check(10, "do: ") )
|
||||
check(120)
|
||||
>>> answer: enough
|
||||
|
||||
## Closures
|
||||
|
||||
@ -219,7 +248,6 @@ As everywhere else, and as expression:
|
||||
|
||||
Notice returned value `void`: it is because of `println` have no return value, e.g., `void`.
|
||||
|
||||
|
||||
Or, more neat:
|
||||
|
||||
var count = 3
|
||||
@ -247,7 +275,8 @@ We can break as usual:
|
||||
}
|
||||
>>> void
|
||||
|
||||
Why `void`? Because `break` drops out without the chute, not providing anything to return. Indeed, we should provide exit value in the case:
|
||||
Why `void`? Because `break` drops out without the chute, not providing anything to return. Indeed, we should provide
|
||||
exit value in the case:
|
||||
|
||||
var count = 0
|
||||
while( count < 50 ) {
|
||||
@ -310,11 +339,13 @@ We can skip the rest of the loop and restart it, as usual, with `continue` opera
|
||||
total
|
||||
>>> 0
|
||||
|
||||
Notice that `total` remains 0 as the end of the outerLoop@ is not reachable: `continue` is always called and always make Ling to skip it.
|
||||
Notice that `total` remains 0 as the end of the outerLoop@ is not reachable: `continue` is always called and always make
|
||||
Ling to skip it.
|
||||
|
||||
## Labels@
|
||||
|
||||
The label can be any valid identifier, even a keyword, labels exist in their own, isolated world, so no risk of occasional clash. Labels are also scoped to their context and do not exist outside it.
|
||||
The label can be any valid identifier, even a keyword, labels exist in their own, isolated world, so no risk of
|
||||
occasional clash. Labels are also scoped to their context and do not exist outside it.
|
||||
|
||||
Right now labels are implemented only for the while loop. It is intended to be implemented for all loops and returns.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user