ion is a multi-purpose, statically-typed programming language with a focus on productivity.
Here is a classic hello world in ion:
import "std/io"
func main() {
std::io::println("Hello world!")
}
Any ion program starts at the main entry point and then executes linearly.
The syntax for variable declarations is:
var my_variable: string = "Hello"
The assignment part is optional only if the type is a primitive with a default value:
Type | Default value |
---|---|
string | "" |
int | 0 |
bool | false |
char | '\0' |
Along with the 4 primitive types previously cited and custom structs, the built-in types are:
Type | Syntax |
---|---|
array | []type |
map | [key_type]value_type |
const ref | &type |
mut ref | @type |
my_variable = "new text"
my_array[4] = "another value"
my_array[] = "new item in array"
my_ref = @some_var
*my_ref = "new content"
func my_function(param1: Type1, param2: Type2 = "default_value") -> ReturnType {
...
}
struct MyStruct {
field1: Type1,
field2: Type2
}
var my_var: MyStruct = new MyStruct {
field1: value1,
field2: value2
}
var my_return: ReturnType = my_function(arg1, arg2)
std::io::println(my_struct.field1)
if condition {
...
} else if other_condition {
...
} else {
...
}
while condition {
...
}
for item in my_array {
...
}
for char in my_string {
...
}
import "relative/path/to/file"
func main {
relative::path::to::file::my_function()
}
print(any)
readln() -> string
std::io::println(string)
std::io::read_int() -> int
std::conv::char_to_int(char) -> int
std::conv::str_to_int(string) -> int
std::math::pow(int, int) -> int
ion my_source_file.ion
Note: for now, your files have to be placed alongside the executable, as well as the std folder.