λ SCHEME RUNE DIFFICULTY: Adept Behavioral

The Memento

Capturing and restoring the fleeting state of temporal anomalies.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Divination // Chronomancy
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// SCHEME PATTERN //
(define (make-temporal-entity init-state)
  (let ((state init-state))
    (define (dispatch msg . args)
      (case msg
        ((set-state!) (set! state (car args)))
        ((save) (lambda () state))
        ((restore) (set! state ((car args))))
        ((get-state) state)))
    dispatch))

(define anomaly (make-temporal-entity 'stable))
(define memento (anomaly 'save))
(anomaly 'set-state! 'chaotic)
(anomaly 'restore memento)

By utilizing a closure to capture the lexical environment’s current state, we effectively bottle time, ready to be poured back into the entity.

Runic Tags: #behavioral #scheme #closures #state-preservation