Sayed's Blog

minerva > docs > users > features

Features

Variables

var message = "Hello world";

Block expressions

var message = {
	"Hello world";
};

If Statements

var age = 20;

if (age > 18) {
	print "You are an adult";
};

If Expressions

var ageCategory = 
	if (age < 18)
		"minor"
	else
		"adult";

While Statements

var iterations = 0;

while (iterations < 10) {
	print iterations;
	iterations = iterations + 1;
}

Until Statements

var iterations = 0;

until (iterations == 10) {
	print iterations;
	iterations = iterations + 1;
}

Functions

function foo() => {
	print "Hello World!";
};

function double(number: Int) => number * 2;

var square = function (number: Int) => number * number;

function factorial(number: Int) : Int =>
	if (number == 0) 1
	else number * factorial(number-1);

foo(); // expect "Hello World!"
print double(4); // expect 8
print square(3); // expect 9
print factorial(5); // expect 120

Match Statements / Expressions

function fibonacci(number: Int): number => 
	match(number) {
		0 => 1;
		1 => 1;
		else => fibonacci(number-1) + fibonacci(number-2);
	};

Classes

// constructor parameters
// those prefixed with var are automatically set as fields
class Parent(var name: String, message: String) {
	constructor {
		print message;
	};
	
	function printName() => {
		print this.name;
	};
};

class Child(name, var age: Int) extends Parent(name) {
}

	function printInfo() {
		this.printName();
		print this.age;
	};
};

var child = Child("John", 25);
child.printInfo();

Type matching

var magic: Int | String | (Int)=>String = "hmm";

print typematch(magic) {
	Int => magic;
	String => magic;
	(Int)=> String => magic(3);
}

    © 2023