# Getting started
## Introduction
AiScript is a programming language.
This document assumes that you already have some programming knowledge.
Therefore, I will only write about the syntax and specifications of AiScript, and leave out the description of programming itself.
## Hello, world!
In AiScript, it is written as follows:
```
print("Hello, world!")
```
`print( ~ )` is a function call. The name of the function to be called is written before the parentheses, and the arguments are written inside the parentheses.
If there are multiple arguments, they are listed separated by `,`.
The details of the function are described later.
`"~"` is a string literal. Anything enclosed in `"` is a string.
Incidentally, `print( ~ )` has a sugar-coated syntax and can be written as follows:
```
<: "Hello, world!"
```
## Comments
AiScript comments start with `//`.
Comments do not affect the behavior of the program.
```
// this is a comment
```
## Primary object
| Type | Form | Example of literal |
| string | str | "kawaii" |
| numeric | num | 42 |
| truth-value | bool | true/false |
| array | arr | ["ai" "chan" "cute"] |
| object | obj | { foo: "bar"; a: 42; } |
| null | null | null |
| function | fn | @(x) { x } |
## Variables
### Declaration
The variable declaration is written as follows:
```
#message = "Hello"
```
Write the name of the variable after `let` and the value after `=`.
In AiScript, variables declared in this way are immutable. In other words, you cannot change the value of a variable later.
To create a variable that can be reassigned, declare the variable with `var` instead of `let`. Example:
```
// Declare a mutable variable.
var message = "Hello"
// reassignment
message = "Hi"
// Reassigning again
message = "Yo"
```
### Reference
When referring to the value of a variable, simply write the name of the variable:
```
print(message)
```
## Array
Enumerate expressions in an array `[]`, separated by spaces.
```
["ai" "chan" "kawaii"]
```
To access an element of an array, write `[]`. The index starts at 0.
```
let arr = ["ai" "chan" "kawaii"]
<: arr[0] // "ai"
```
## Object
```
{
foo: "bar"
answer: 42
nested: {
some: "thing"
}
}
```
## Arithmetic operation
The operation is
```
(1 + 1)
```
This is a sugar-coated syntax for function calls. This is the sugar-coated syntax for function calls, and is actually interpreted as such:
```
Core:add(1, 1)
```
All of the functions listed below can be used as sugar-coated syntax such as `(1 + 1)`.
| Function | Operator | Meaning |
Core:add | + | addition |
Core:sub | - | subtraction |
Core:mul | * | multiplication |
Core:pow | ^ | exponentiation |
Core:div | / | division |
Core:mod | % | remainder |
Core:eq | == | equal |
Core:and | && | and |
Core:or | || | or |
Core:gt | > | greater than |
Core:lt | < | less than |
## Block
A block is a collection of processes, written as `eval { ~ }`.
The expression written at the end of the block will be returned as the value of the block.
```
let foo = eval {
let a = 1
let b = 2
(a + b)
}
<: foo // 3
```
The block itself is also a formula.
## Conditional branching
The conditional branch in AiScript is written as follows:
```
if (a == b) {
<: "a is equal to b"
}
```
After `if`, write an expression (condition) that returns a bool, followed by an expression (then clause) that will be evaluated if the condition is met.
You can add `else` after the `then' clause and add an expression to handle the case when the condition is not met:
```
if (a == b) {
<: "a is equal to b"
} else {
<: "a is not equal to b"
}
```
You can also write conditional expressions after `elif` to make multiple conditional decisions:
```
if (a == b) {
<: "a is equal to b"
} elif (a > b) {
<: "a is grater than b"
} else {
<: "a is less than b"
}
```
Since these conditional branches are expressions, they can return a value in the block:
```
<: if (a == b) {
"a is equal to b"
} elif (a > b) {
"a is grater than b"
} else {
"a is less than b"
}
```
## Loop
To iterate in AiScript, write the following:
```
for (let i, 100) {
<: i
}
```
After `for`, write the name of the iterator variable, and after `,` write an expression that returns the number of iterations. Write the process to be repeated in the block that follows.
The iterator variable can also be omitted:
```
for (100) {
<: "yo"
}
```
## Loop (array)
You can use `each` to repeat items in an array:
```
let items = ["a" "b" "c"]
each (let item, items) {
<: item
}
```
## Function
### Function definition
Write the following:
```
@fn(x) {
(x * 2)
}
```
Write the function name after `@` and the argument definition in parentheses. After that, the block becomes the process of the function.
### return
The value of the expression written at the end of the function will be the return value of the function, but if you want to return a value in the middle of the function, use `return`.
## Template
You can embed variables and expressions in a string:
```
let ai = "kawaii"
<: `Hello, {ai} world!`
```
## Metadata
This function allows you to embed metadata in AiScript files.
```
### {
name: "example"
version: 42
keywords: ["foo" "bar" "baz"]
}
```
# Examples
## FizzBuzz
```
for (let i, 100) {
<: if (i % 15 == 0) "FizzBuzz"
elif (i % 3 == 0) "Fizz"
elif (i % 5 == 0) "Buzz"
else i
}
```