Reflect

Overview

Reflect is a practical multi-paradigm language suitable for application code and system code alike. The emphasis is on a simple, but very expressive, core language combined with high-performance, memory safety and a strong type system. Functional, procedural and object oriented programming styles are supported, combined with powerful meta programming capabilities. Code can be compiled or interpreted, depending on the usage scenario.

Example

function main()
{
	// familiar C inspired syntax
	print("Hello, World!");

	// functional and imperative range based operations
	// and interpolated strings - prints all even numbers
	// from zero to 18
	for (num; (0 .. 10).map(i => 2 * i))
		print("$(i+1). number: $(num)");

	// constants and variables
	let pi = 3.14;
	var n = 5;
	n += 4;
	print(n); // prints 9

	// powerful but straightforward meta programming
	// (no templates or macros)
	let basename = "counter";
	meta for (i; 0 .. 3)
		var #"$(basename)_$(i)": int;
	counter_0 = 1;
	counter_1 = 3;
	counter_2 = 4;

	// exception-like return value based error handling
	try print(divide(12, 3)!);
	catch (ArithmeticError e) {
		switch (e.kind) {
			case .divideByZero:
				print("Attempted to divide by zero!");
			case .unknown:
				print("Unknown error during division: ",
					e.unknownValue);
		}
	}
}

@error(ArithmeticError)
function divide(a: int, b: int)
{
	if (b == 0)
		throw ArithmeticError.divideByZero();
	if (b < 0)
		throw ArithmeticError.unknown(
			"Unsupported division by negative number");
	return a / b;
}

enum ArithmeticError {
	divideByZero: void,
	unknown: string
}

Design Goals

Inspiration

Sharing similar goals, the D programming language probably had the most direct influence on the language -- it does a lot of things right and is a huge improvement over C++ in terms of providing a clean and intuitive syntax, while at the same time achieving a big advancement in language expressiveness, especially compared to C++ standards prior to C++23. Unfortunately, the C/C++ heritage nowadays is also what keeps D from getting closer to an ideal language, especially due to the more recent direct C++ interfacing support and its template and string mixin based approach to meta programming.

Rust should also be mentioned for its approach to memory safety, even though it doesn't work quite the same, it has the same goal of guaranteeing memory safety in the presence of manual memory management and multi-threaded data access.

Apart from these, the language syntax has similarities with multiple other modern, functionally influenced languages, such as Swift and Kotlin. There are also other bits and pieces found less popular languages, such as Scala, Zig, Nim or Z, but those are mostly just co-evolutionary features.

Implementation Status

Explanation

Status