λ SCHEME RUNE DIFFICULTY: Apprentice Creational

The Factory Method

Delegating the manifestation of magical entities to specialized sub-closures.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Factory Method
ARCANUM SCHOOL: Conjuration // Summoning
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCHEME PATTERN //
(define (make-spawner spawn-fn)
  (lambda (type)
    (let ((entity (spawn-fn type)))
      (display "Summoned: ") (display entity) (newline)
      entity)))

(define elemental-spawner
  (make-spawner
    (lambda (type)
      (case type
        ((fire) 'fire-elemental)
        ((water) 'water-elemental)
        (else 'unknown-entity)))))

Higher-order functions allow specialized summoning logic to be injected into generalized creation rituals.

Runic Tags: #creational #scheme #higher-order-functions