Variables


Variables are identifiers for an area of memory of width defined by its type.

In simpler words, a variable is a container that can have a value in it. It has a data type, which specifies the kind of data it can contain, and that cannot change for the lifetime of the variable. There may not be two variables with the same name in the same scope.

Data types


[name] implements the following primitive data types:

In addition to the primitive data types, the user can define custom data types (next page [HEY NILS MAYBE PUT A LINK HERE IDFK]), enums (a bit ahead) and generics (again, next page).

Also, modifiers can be added to change the data type entirely:

Syntax


In [name], variable declaration is done as such:

var pragmasopt type name;

Variables are automatically zeroed at declaration!

A variable can also be assigned a value at declaration time. In this case, the data type can be omitted and inferred by the compiler. Note that this may produce undesired results at times, so (especially in low level programming) be aware of data types.

The value may need code execution, in which case it is assigned 0 in memory and calculated when execution starts, before calling Main.

var pragmasopt typeopt name = value;

A variable can be defined constant, so that it can't change. In this case it requires a value, and:

  1. if the value can be resolved at compilation time, the variable behaves like an alias and is replaced by its value directly.
  2. if the value needs code execution, the variable behaves like a normal variable, except the value cannot be modified.

const pragmasopt typeopt name = value;

Examples


var u64 myVar;

Declaring a variable of name myVar and type u64.

var myVar = 15;

Declaring a variable of name myVar and letting the compiler guess. In this particular case, the compiler will guess i64.

const u8 true = 1; const u8 false = 0;

Actual code in the bool library, defining true and false as "aliases" for 1 and 0

Behaviour


The default behaviour can be altered using pragmas: