Vult has syntax that may resemble languages like C/C++, Python or JavaScript. In order to declare a function you can use the keyword fun
as follows:
This functions takes no arguments and returns the integer value zero. If you have more than one statement you can use the curly braces {}
to delimit the function body.
As you may have seen, you can declare variables with the keyword val
.
Vult is a static language, this means that every variable has concrete type. Since Vult is focused on numeric computations there are two main types available: real
and int
. You can specify the type of the variables with colon :
as follows:
This specifies that the function receives an argument x
of type int
and returns a value of type int
.
The type annotations are not strictly necessary. Vult has type inference which means that it will try to automatically determine every type based on the use of the variables. We will cover more about the type inference in a different tutorial.
Function in Vult can return multiple values separated by commas. The values can be assigned to multiple variables in a similar way.
As mentioned before, Vult is static and strict. It is not possible to mix operations between reals and integers without making an explicit cast. The following operation is invalid:
The problem here is that the values have different type. The number 1
is of type int
and the number 2.1
is of type real
. In order to perform operations, you need to explicitly cast the values. For example:
By not making automatic conversion of types Vult gives you a more control on the kind of operation you want to perform.
In the following tutorials we will cover more advanced aspects of Vult.