The Vale Programming Language

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.

Hello world!

First, download the latest Vale compiler from the downloads page, and unzip it to a directory, such as ~/Vale.

Then:

  • Put the below code into a .vale file such as ~/myprogram.vale
  • Run the command ~/Vale/valec build mymodule=~/myprogram.vale --output_dir build.
    • See that it created a build directory, with a main executable in it. 0
  • Run the command build/main to run the executable.
vale
import stdlib.*;

exported func main() {
println("Hello world!");
}
stdout
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!

If you get an error "Unable to find program java" then you'll need to install a JDK, we recommend AdoptOpenJDK.

Variables

We can make a variable with the = symbol.

vale
import stdlib.*;

exported func main() {
x = "world!";
println("Hello " + x);

}
stdout
Hello world!

We can change a variable's contents with the set keyword.

vale
import stdlib.*;

exported func main() {
x = "world!";
set x = "Antarctica!";
println("Hello " + x);

}
stdout
Hello Antarctica!

Side Notes
(interesting tangential thoughts)
0

If on windows, the executable will be named main.exe.

1

exported means it can be called by the OS or other languages such as C. See FFI: Externs and Exports for more.

2

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:

  • ~/.bashrc
  • ~/.bash_profile
  • ~/.zshrc

Static Typing & Inference

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.

vale
import stdlib.*;

exported func main() {
a str = "world!";
println("Hello " + a);

}
stdout
Hello world!

Next: Collections