The Visitor Hex
Traversing an abstract syntax tree of magical structures.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Pure Environment Hexes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
let
# Elements (The AST or data structure)
nodeA = { type = "fire"; damage = 50; };
nodeB = { type = "ice"; slow = 30; };
tree = [ nodeA nodeB ];
# The Visitor
powerCalculator = node:
if node.type == "fire" then node.damage * 2
else if node.type == "ice" then node.slow * 1.5
else 0;
# Applying the Visitor (Traversal)
totalPower = builtins.foldl' (acc: node: acc + (powerCalculator node)) 0 tree;
in
totalPower
The Visitor pattern separates an algorithm from the object structure on which it operates. By mapping a specific visitor function across deeply nested derivations or configurations, we can extract metrics or generate metadata without altering the underlying structures.
Runic Tags:
#behavioral
#visitor
#nix
#ast
#traversal