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
- Syntax:
- Functionally oriented, but familiar to users of C-family languages
- Readable and lean code that avoids syntactic clutter and inconsistent or unclear syntax elements
- Simple, context-free grammar that can be implemented as a basic recursive descent parser (LALR(1))
- Expressiveness:
- Powerful, but simple and intuitive, meta programming abilities
- As expressive as possible, without compromising code clarity
- User defined types can fully mimic built-in types
- Mechanical Properties
- Guaranteed memory safety in single-threaded and multi-threaded code, without relying on a garbage collector
- Compiling to native machine code
- Support for directly calling into/from C/C++/Obj-C/D code
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
- π’ fully implemented
- π‘ mostly implemented
- π partially implemented
- π΄ not implemented
Status
- π’ modules
- π’ imports
- π’ public imports
- π’ static imports
- π’ selective imports
- π’ imports
- π’ protection
- π’
public - π’
private - π΄
module - π΄
protected
- π’
- π literals
- π numeric
- π’ decimal integers
- π΄ hexadecimal integers
- π΄ octal integers
- π΄ floating-point
- π strings
- π‘ escaped strings
- π΄ raw strings
- π’ interpolated strings
- π΄ characters
- π΄ literal type prefix/suffix
- π’ arrays
- π’ tuples
- π΄ dynamic literals (
__LINE__,__FILE__etc.)
- π numeric
- π types
- π’ integer types
- π’ floating point types
- π’ pointers
- π’
T[]mapped toArraySlice(T) - π’
a .. bmapped toSpan(T)(a, b) - π’
T[N]mapped to static array type - π’ type type
- π‘
noreturn - π’
struct - π’
enums- π’ value based enums
- π’ type based enums (tagged unions)
- π‘
interface - π΄
class - π aggregate features
- π’ constructors
- π’ default constructors
- π΄ destructors
- π‘ operator overloading
- π’ arithmetic operators
- π’ comparison operators
- π’ default equality operator
- π΄ copy operators
- π΄ move operators
- π’ implicit cast operators
- π’ assignment operators
- π’ default assignment operator
- π’ call operators
- π’ properties
- π’ mapping to getter/setter methods
- π’ using as r-value
- π’ using as l-value
- π΄
@align
- π’ constructors
- π‘ declarations
- π’ declaration scopes
- π’ module
- π’ aggregate
- π’ function
- π’ attributes
- π’ variables (
var) - π’ constants (
let) - π’
alias - π‘ functions
- π’ regular functions
- π’ lambda syntax
- π inline functions
- π’ regular syntax
- π’ lambda syntax
- π΄ closures
- π’ optional parameters
- π’ named parameters
- π variable argument lists
- π’ parser implementation
- π’ tuple based
- π΄ array based
- π΄ C style
- π’ overload resolution based on partial function type parameters
- π’ declaration scopes
- π’ flow control
- π’
if/else - π’
for- π’ C style
- π’ Range for-each
- π’
loop - π‘
switch
- π’
- π compile-time flow control
- π’
meta if - π‘
meta for - π΄
meta switch
- π’
- π‘ error handling
- π’
Errortype - π’ implicit error return value translation
- π’
try/catch - π΄ enforcing
@errorannotations and checkingthrowtypes - π΄ throwing and catching partial error types
- π’
- π semantic rules
- π‘ implicit type conversion rules
- π‘ interface conformance
- π΄ symbol shadowing checks
- π΄ nullable/explicit initialization checks
- π΄ memory safety
- π΄
@safe/@unsafeattribute enforcement
- π΄
- π΄ uncaught error annotation checking
- π’ tuples
- π’ mixins
- π΄
meta()expressions - π unit tests
- π΄ code generation
- π΄ target platform specific endianness and pointer/size types during IR evaluation
- π΄ SSA intermediate representation compilation
- π΄ C/D code generation backend
- π΄ machine code generation backend (LLVM)