⚙️ CAIRO RUNE DIFFICULTY: Archmage Behavioral

The Visitor

Injecting new analytics into abstract syntax trees of constraints.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Visitor
ARCANUM SCHOOL: Divination // Inspection
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CAIRO PATTERN //
#[derive(Drop)]
enum Node {
    Constraint: felt252,
    Variable: felt252,
}

trait IVisitor<T> {
    fn visit_constraint(ref self: T, val: felt252);
    fn visit_variable(ref self: T, val: felt252);
}

#[derive(Drop)]
struct CostVisitor { cost: u32 }
impl CostVisitorImpl of IVisitor<CostVisitor> {
    fn visit_constraint(ref self: CostVisitor, val: felt252) { self.cost += 10; }
    fn visit_variable(ref self: CostVisitor, val: felt252) { self.cost += 1; }
}

Wanders through the labyrinth of constraints, collecting metadata and invoking new effects without mutating the nodes themselves.

Runic Tags: #cairo #design-pattern #visitor