Article by Ayman Alheraki on January 11 2026 10:37 AM
To crystallize the goals and philosophy of our new C-style language, this section introduces example source code written in the proposed syntax and semantics of the language. This code is not only illustrative of its intended usage but also highlights the motivations behind its design, rooted in the practical capabilities of C++20/23 which powers its interpreter.
These examples are deliberately designed to reflect the essential traits of the language:
Simplicity and clarity in syntax
Safety and deterministic behavior
Explicit memory and ownership management
Compile-time evaluation and static typing
Concurrency primitives built into the language
Minimal standard runtime abstractions
The language borrows its surface syntax from the C/C++ family but enforces modern principles such as immutability by default, explicit mutability, explicit ownership transfer, and built-in safe types like Option, Result, and Slice.
fn main() -> int { print("Hello, World!"); return 0;}Key Observations:
fn is the keyword for function definition
main returns an integer, explicitly
print() is a built-in function in the minimal standard library
Semicolon enforces clear statement boundaries
No global side-effects or preprocessor use
fn demo() { let x: int = 10; // Immutable by default let mut y: int = 20; // Mutable with 'mut'
y = y + x; print(y); // Output: 30}Design Notes:
let declares a variable; mut marks it mutable
No implicit type promotion
All variables are block-scoped
Encourages value-oriented programming, discourages shared mutability
fn safe_divide(a: int, b: int) -> Option<int> { if b == 0 { return none; } return some(a / b);}
fn use_divide() { let result = safe_divide(10, 2); if result is some(val) { print("Result: ", val); } else { print("Division by zero"); }}Conceptual Design:
Option<T> is a built-in tagged union: some(T) or none
Pattern matching is minimal but expressive
Avoids nulls entirely by requiring explicit handling
Internally backed by std::optional in the C++ interpreter
const fn factorial(n: int) -> int { if n <= 1 { return 1; } return n * factorial(n - 1);}
fn main() { const fact_5: int = factorial(5); // Computed at compile time print(fact_5); // Output: 120}Engine Behavior:
const fn marks functions evaluable at compile-time
Can be folded by the interpreter before execution
Uses constexpr or consteval under the hood in C++20/23
Supports embedded and systems programming via deterministic computation
struct Point { x: float; y: float;}
fn distance(p: Point) -> float { return sqrt(p.x * p.x + p.y * p.y);}
fn example() { let origin = Point { x: 3.0, y: 4.0 }; print("Distance: ", distance(origin)); // Output: 5.0}Design Insight:
Structs have named fields and no implicit constructors
No inheritance; instead, structural or trait-based behavior
Internally modeled using struct and std::variant where polymorphism is required
trait Addable { fn add(self, other: Self) -> Self;}
fn sum<T: Addable>(a: T, b: T) -> T { return a.add(b);}Semantics:
Traits define required behavior (similar to C++ concepts or Rust traits)
Generics with constraint T: Addable
Enforced at compile-time; no runtime overhead
Backed by concepts and requires clauses in C++20
fn compute() -> int { let mut result: int = 0; for i in 0..100 { result = result + i; } return result;}
fn parallel_sum() { let t1 = spawn compute(); let t2 = spawn compute();
let r1 = join t1; let r2 = join t2;
print("Total: ", r1 + r2);}Runtime Behavior:
spawn creates a concurrent task (internally backed by std::jthread)
join blocks and retrieves the result
No shared mutable state; each function returns its own value
Thread-safe by design with no race condition primitives exposed by default
fn open_file(path: string) -> Result<File, string> { if path == "" { return err("Empty path"); } return ok(File {});}
fn main() { let file = open_file("log.txt"); if file is ok(f) { print("Opened successfully"); } else if file is err(e) { print("Error: ", e); }}Design Philosophy:
No exceptions
All errors must be handled explicitly
Result<T, E> is modeled using a discriminated union
Backed internally by std::variant or equivalent C++ construct
fn print_slice(data: slice<int>) { for i in 0..data.len { print(data[i]); }}
fn use_slice() { let arr = [1, 2, 3, 4]; print_slice(arr[1..3]); // Prints: 2, 3}Safety Model:
slice<T> is a view, not an owning container
All indexing is bounds-checked by default
Internally uses std::span<T> with range validation in debug builds
module math;
fn square(x: int) -> int { return x * x;}cppCopyEditimport math;
fn main() { print(math::square(5)); // Output: 25}Module Philosophy:
File = module; explicit import/export
No preprocessor; no text-based inclusion
Namespaces resolved statically; no symbol collisions
Mirrors C++20 modules and supports layered build architecture
The example code demonstrates a realistic and coherent C-style language that learns from the best practices of recent systems languages while avoiding their complexity and performance compromises. Each feature shown is backed by real capabilities in C++20/23, ensuring that both the interpreter and language design remain aligned with proven techniques in modern software engineering.
The examples also reflect our language’s goals:
Simplicity with clarity
Explicit memory and concurrency handling
Compile-time power without hidden magic
Strong, safe typing with low abstraction overhead