Welcome to Vale, the fast, safe, and simple programming language. This introduction will show how to write a basic program in Vale.
This reference assumes that you are familiar with basic programming concepts, and at least one other imperative language (like C, Java, Python, etc).
Vale is still in alpha, which means it's a preview; you can write programs in it, but some of the features that make it easy aren't yet available.
First, download the latest Vale compiler from the downloads page, and unzip it to a directory, such as ~/Vale.
Then:
import stdlib.*;
exported func main() {
println("Hello world!");
}
Hello world!
Every Vale program must have an exported main function like the above. 1
Every source file must belong to a module. That's what the mymodule= is for. For now, you can put mymodule= in front of all of your .vale files (or directories containing .vale), and in Modules we'll explain more about what modules are.
Instead of:
~/Vale/valec build mymodule=~/myprogram.vale --output_dir build
You can say:
valec build mymodule=~/myprogram.vale --output_dir build
if you put ~/Vale in your PATH. 2 We recommend it!
We can make a variable with the = symbol.
import stdlib.*;
exported func main() {
x = "world!";
println("Hello " + x);
}
Hello world!
We can change a variable's contents with the set keyword.
import stdlib.*;
exported func main() {
x = "world!";
set x = "Antarctica!";
println("Hello " + x);
}
Hello Antarctica!
If on windows, the executable will be named main.exe.
exported means it can be called by the OS or other languages such as C. See FFI: Externs and Exports for more.
To add ~/Vale to your PATH in Linux and Mac, type:
export PATH=$PATH:~/Vale
This will only affect the current session. However, you can make this automatically happen in every session, by adding the command to a file that run automatically on startup. On Linux and Mac, that file is usually one of:
Vale is a statically typed language, which means the type of every variable and struct member is known at compile-time.
In this example, a is of type str. If we want, we can specify it explicitly after the variable's name.
...though we usually leave it out, because Vale uses type inference to figure out the type of a for us.
import stdlib.*;
exported func main() {
a str = "world!";
println("Hello " + a);
}
Hello world!
Next: Collections