🐺 WOLFRAM ALCHEMY DIFFICULTY: Adept Behavioral

The Interpreter Incantation

Defining a grammer and evaluating a domain-specific arcane dialect.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Interpreter
ARCANUM SCHOOL: Divination // Linguistics
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// MATHEMATICA PATTERN //
(* The Grammatical Rules for the Arcane Dialect *)
ClearAll[InterpretSpell];

(* Terminal Expressions *)
InterpretSpell["IGNIS"] := "Fire";
InterpretSpell["AQUA"] := "Water";

(* Non-Terminal Expressions *)
InterpretSpell[{"MAGNUS", element_String}] := "Greater " <> InterpretSpell[element];
InterpretSpell[{"PARVUS", element_String}] := "Lesser " <> InterpretSpell[element];
InterpretSpell[{"DUAL", e1_, e2_}] := 
  InterpretSpell[e1] <> " and " <> InterpretSpell[e2];

(* Catch-all for parsing lists natively *)
InterpretSpell[expr_List] := InterpretSpell /@ expr;

(* Usage *)
Print[InterpretSpell[{"MAGNUS", "IGNIS"}]];
Print[InterpretSpell[{"DUAL", {"PARVUS", "AQUA"}, "IGNIS"}]];
Runic Tags: #interpreter #behavioral #domain-specific #rules