The Prototype
Clone existing spells to create new ones via content-addressed deep copies.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Transmutation // Cloning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
structural type Spell = Spell Text Nat
cloneSpell : Spell -> Spell
cloneSpell s = match s with
Spell name power -> Spell name power
mutatePower : Nat -> Spell -> Spell
mutatePower p s = match s with
Spell name _ -> Spell name p
In languages that suffer from the ravages of mutable memory, cloning an object is fraught with peril. In Unison, all structures are inherently immutable and content-addressed. The Prototype pattern is fundamentally native to the language: a simple function that matches the previous form and yields a new one, structurally identical yet distinct in its true hash.
Runic Tags:
#creational
#prototype
#unison
#content-addressed