Reflect

Functions

⚠️ TODO

Example:

function square(x) => x ^^ 2;

function square2(x: int) : int
{
	return x ^^ 2;
}

assert(square(3) == 9);
assert(square2(3) == 9);

Normal Functions

⚠️ TODO

Parameter Type Inference

⚠️ TODO

Typed Parameters

Generic Typed Parameters

Constrained Parameters

Partially Typed Function Parameters

Unconstrained Parameters

Parameter Reverse Overload resolution

⚠️ TODO

Return Type Inference

⚠️ TODO

Variadic Parameters

⚠️ TODO

Tuple Based

function printFormatted(string format, arguments...) {}
printFormatted("The %s is %s", "answer", 42);

Array Slice Based

function addItems(items...: int[]) {}
addItems(1, 2, 3);
addItems([1, 2, 3]);
addItems(items: [1, 2, 3]);

Static Array Based

function setCoordinates(coordinates...: int[3]) {}
setCoordinates(1, 2, 3);
setCoordinates([1, 2, 3]);

C-Style

extern(C) function printf(const(char)* format, ...): int;

Universal Function-Call Syntax

When calling a normal function, instead of writing all arguments in parenthesis, the first argument may instead be written in front of the function, resembling a method call. Conversely, a method can also be called by referencing the method name as a regular function outside of the aggregate and passing the aggregate as the first argument.

This alternative syntax naturally allows to write "extension functions", as well as functional call chains.

Example:

struct Point {
	var x: int;
	var y: int;

	method clear() { x = 0; y = 0; }
}

function moveRight(ref point: Point, amount: int)
{
	point.x += amount;
}

var pt = Point(10, 10);

// regular function call
moveRight(5);
assert(pt == Point(15, 10));

// regular method call
pt.clear();

// function called as method
pt.moveRight(5);
assert(pt == Point(15, 10));

// method called as function
clear(pt);

Inline Functions

⚠️ TODO

Closures

⚠️ TODO