87 lines
1.9 KiB
Markdown
87 lines
1.9 KiB
Markdown
# Kyn Syntax
|
|
|
|
This document details syntax of provided Kyn modules.
|
|
|
|
Call a module by writing it's name, then the arguments for the module.
|
|
|
|
Substitute the output of a module into another module's arguments by enclosing the call in `(`parenthases`)`.
|
|
|
|
Access a variable by prefixing it's name with a `$` dollar sign.
|
|
|
|
## Input/Output
|
|
|
|
### print
|
|
|
|
Prints all the arguments provided to the console.
|
|
|
|
Example: `print "Hello!"`
|
|
|
|
### println
|
|
|
|
Prints all the arguments provided to the console, appending a newline after.
|
|
|
|
Example: `println "Hello!"`
|
|
|
|
### input
|
|
|
|
Gets a line of input from the console.
|
|
|
|
Example: `input` (this does nothing but prompt the user)
|
|
|
|
Another example: `let userInput = (input)`
|
|
|
|
## Data
|
|
|
|
### let
|
|
|
|
Defines a variable to the value provided.
|
|
|
|
Example: `let myVar = "Hello!"`
|
|
|
|
## Computations
|
|
|
|
### math
|
|
|
|
Computes a mathematical expression. Supports addition (+), subtraction (-), multiplication (*), division (/), power to (^) and mod (%).
|
|
|
|
Example: `math 4 * 3 + 12 / 4 - 5 ^ 3`
|
|
|
|
### compare
|
|
|
|
Compares two values. Supports equal (==) and inequal (!=) on all values. Supports greater than (>), greater than or equal to (>=), lesser than (<), and lesser than or equal to (<=) for numbers.
|
|
|
|
## Control Flow
|
|
|
|
### exit
|
|
|
|
Exits the program with a return code. If no return code or an invalid return code is provided, exits with code 0. Otherwise, exits with given code.
|
|
|
|
### if
|
|
|
|
Runs a module. If the output of that module is 0 or "false", skips the code in that block. If an `else` block is provided after, that is running instead. Otherwise, the code inside the `if` block is ran.
|
|
|
|
Example:
|
|
|
|
```
|
|
if compare 1 == 1 {
|
|
println "1 is the same as 1"
|
|
} else {
|
|
println "1 is not the same as 1"
|
|
}
|
|
```
|
|
|
|
### while
|
|
|
|
Runs a module. If the output of that module is 0 or "false", skips the code in that block. Otherwise, loops the block until the module ran is 0 or "false".
|
|
|
|
Example:
|
|
|
|
```
|
|
let number = 0
|
|
|
|
while compare $number <= 10 {
|
|
number = ($number + 1)
|
|
println $number
|
|
}
|
|
```
|