✨ ARCANUM RUNE DIFFICULTY: Apprentice Creational

The Singleton Hex

Ensure only one instance of an arcane artifact exists across the entire realm.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Singleton
ARCANUM SCHOOL: Conjuration // Monolithic Bindings
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
use fmt;

type CoreCrystal = struct {
	power_level: uint,
};

let instance: CoreCrystal = CoreCrystal { power_level = 9000 };

fn get_crystal() *CoreCrystal = {
	return &instance;
};

export fn main() void = {
	let crystal1 = get_crystal();
	let crystal2 = get_crystal();
	crystal1.power_level = 9001;
	fmt::printfln("Crystal 2 power: {}", crystal2.power_level)!;
};

The Singleton binds a unique entity into global memory, ensuring that no matter how many threads or scripts reach for it, they all touch the exact same metaphysical anchor.

Runic Tags: #creational #singleton #simple-systems-hexes