λ SCHEME RUNE DIFFICULTY: Apprentice Creational

The Prototype

Cloning mystic schematics using pure data distillation.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Prototype
ARCANUM SCHOOL: Illusion // Shadowmancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCHEME PATTERN //
(define (clone-spell prototype changes)
  (let loop ((proto prototype) (mods changes) (result '()))
    (if (null? proto)
        (reverse result)
        (let* ((key (caar proto))
               (val (cdar proto))
               (mod (assq key mods)))
          (loop (cdr proto)
                mods
                (cons (if mod mod (cons key val)) result))))))

(define base-fireball '((damage . 10) (radius . 5) (element . fire)))
(define greater-fireball (clone-spell base-fireball '((damage . 50) (radius . 15))))

Using associative lists and tail-recursive deep copies, prototypes are infinitely malleable.

Runic Tags: #creational #scheme #alist #pure-functions