✨ GLEAM ALCHEMY DIFFICULTY: Apprentice Behavioral

The Interpreter

Parsing arcane runes into executable operations.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Rune Parsing
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// GLEAM PATTERN //
pub type Expr {
  Num(Int)
  Add(Expr, Expr)
  Multiply(Expr, Expr)
}

pub fn evaluate(expr: Expr) -> Int {
  case expr {
    Num(n) -> n
    Add(a, b) -> evaluate(a) + evaluate(b)
    Multiply(a, b) -> evaluate(a) * evaluate(b)
  }
}

The Interpreter

Pattern matching recursively over abstract syntax trees is the bread and butter of functional programming. The interpreter is native to Gleam.

Runic Tags: #divination #interpreter #gleam