Concept


Variables in Alusus is just a places that allocated in the memory for store data when we execute the program. And the type we gave it to the variables determines the data type that could be stores in the allocated memory for that variable.

To defined a variable we use the reserved word `def` followed by the variable name then a `:` and finally the variable's name.

def variable_name: Data_type;

Setting the value of a variable is done either directly when we defined the variable, in the following way:
def variable_name: Data_type = value;

Or after we define it, by using `=` operator, in the following way:
variable_name = value


Example:
import "Srl/Console.alusus";
use Srl;
def age: Int = 40;
Console.print("I am %d years old.\n", age);
/* I am 40 years old. */

Naming Guidelines


  1. The name of the variable can consist of upper case letters A-Z, lower case letters a-z, digits 0-9, or underscore `_`.
  2. The first letter must be a letter or an underscore.
  3. Spaces cannot be used in variables' names.
  4. Special symbols is not allowed to be used in variables' names, like `#` or `$`.
  5. Reserved words (like `def`) cannot be used as a variable name in Alusus.
  6. Variables' names are case sensitive.
  7. Variables' values could be numerical or alphabetical.
  8. Alusus language is case sensitive.

Basic Types


The basic types for variables in Alusus are almost the same as any programming language, and they are:
`Bool`, `Float`, `Char`, `Word`, `Int`, in addition to `ArchInt` and `ArchWord`.

Note: Alusus defines `int` as an alias for `Int`, which means there is not difference between `int` and `Int` when defining an integer variable, and the same holds for other basic types, which means `char` is an alias for `Char` and `word` is an alias for `Word` etc.

Int
This class is used to store an integer number, which means a number without a decimal point. We will define a variable with integer type. By default it will allocate 32 bit in the memory:
def my_number: int // 32 bits

To change the number of bits allocated in the memory we use square brackets [n], where `n` represents the number of bits that will be allocated, as follows:
def my_int_number: int[16] // 16 bits

We could also, use `ArchInt` class which defines an integer with number of bits that matches the architecture of the system. Which means 32 on 32bit systems and 64 on 64bit systems.
def my_int_number: ArchInt;

Example: A program that adds two integers:
import "Srl/Console.alusus";
use Srl;
def a: Int = 3; // define an integer variable and assign a value directly to it.
def b:int; // define another integer variable.
b=8 // assign the value 8 to variable `b`
def sum:int=a+b; // store the result of sum in a new integer variable.
Console.print(sum); // print the result

Float
This class is used to store a number that can contain a decimal point. To define a variable with this type we use the same previous way:
def my_float_number: float = value;

Example:
import "Srl/Console.alusus";
use Srl;
def x1: float[64]=0.3;
def x2: float[64]=0.6;
def sum: float[64]=x1+x2;
Console.print("x1+x2 = %f",sum); // x1+x2 = 0.900000

To control the number of digits after the decimal point we could write:
Console.print("x1+x2 = %0.1f",sum); // x1+x2 = 0.9
Console.print("x1+x2 = %0.2f",sum); // x1+x2 = 0.90

In case your system architecture is 32 and you could not specify the number of bits for `float` type as 64, you could use the following alternative solution:
import "Srl/Console.alusus";
use Srl.Console;
def float_num: float; // by default it will be 32 bit
float_num=getFloat (); // enter the number
print("%f", float_num~cast[Float[64]]); // cast on print

Word
Used to represent a positive integer number. Number of bits is defined inside square brackets. Specifying the number of bits is optional, by default it will take 32 bit. Which means the same as `Int` class. It is also possible to use the class `ArchWord` in a similar way to the class `ArchInt` to set the number of bits that match the system architecture.

Char
This class is used to store a character or to store an integer that its value represents a character (the number of that character in ASCII). To define a variable from this class we use the same previous way. This class is just an alias for `Word[8]`.
def a: char = 65;
Console.print("%c", a); // A

Bool
This class is used to store either the value 1 (true) or the value 0 (false). Its value is binary, and it is just an alias for `Word[1]`.


ptr
We will talk about it in a dedicated lesson.

Note: It is also possible to define constants in the same way, but putting the value itself instead of the type, this possible for integers, floating point numbers, and strings. As shown in the next example:

def hello: "Hello World";
def pi: 3.141592;
def daysPerWeek: 7;

Class Types


Class types are types defined by the user (or a standard library) using the `class` keyword. Among the most important class types are `Array` and `String`. Instances of class types are called objects. We will discuss these types later in this tutorial.