λ SCHEME RUNE DIFFICULTY: Adept Behavioral

The Chain of Responsibility

Passing the magical burden down a lineage of elder wardens.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Chain of Responsibility
ARCANUM SCHOOL: Abjuration // Warding
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCHEME PATTERN //
(define (make-ward element next-ward)
  (lambda (attack)
    (if (eq? (car attack) element)
        (string-append "Absorbed " (symbol->string element) " attack!")
        (if next-ward
            (next-ward attack)
            "Attack breached all wards!"))))

(define master-ward
  (make-ward 'fire
    (make-ward 'water
      (make-ward 'lightning #f))))

(master-ward '(lightning 50))

A chain of closures delegates the request dynamically, passing the invocation down the lineage until a capable warden handles it.

Runic Tags: #behavioral #scheme #recursion #closures