The Prototype in AWK
Clone associative arrays to duplicate intricate entity states without re-evaluation.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Biomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
# The cloning ritual
function clone_entity(src, dest, k) {
for (k in src) dest[k] = src[k]
}
BEGIN {
# The archetypal elemental
proto_fire["element"] = "Fire"
proto_fire["damage"] = 50
proto_fire["duration"] = 5
# Clone the prototype to create a specific minion
clone_entity(proto_fire, minion1)
# Mutate the clone's properties slightly
minion1["damage"] = 75
minion1["name"] = "Ember Fiend"
print minion1["name"] " burns for " minion1["damage"] " damage!"
print "Archetype damage remains: " proto_fire["damage"]
}
In the domain of AWK, native deep-copy mechanisms for arrays do not exist. The Prototype pattern is actualized through iteration, allowing the scribe to duplicate complex multi-dimensional states and spawn variations of standard text-processing configurations.
Runic Tags:
#awk
#text-processing
#creational