The Memento
Capturing the volatile state of an active matrix for chronomantic restoration.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Divination // Time Weaving
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CODEX INCANTATION //
package main
import "core:fmt"
// The Memento (Opaque State)
Matrix_Snapshot :: struct {
energy: int,
frequency: f32,
// In a real system, we'd deep copy dynamic data here
}
// The Originator
Arcane_Matrix :: struct {
energy: int,
frequency: f32,
}
create_snapshot :: proc(m: ^Arcane_Matrix) -> Matrix_Snapshot {
fmt.println("Matrix: Saving chronomantic snapshot.")
return Matrix_Snapshot{
energy = m.energy,
frequency = m.frequency,
}
}
restore_snapshot :: proc(m: ^Arcane_Matrix, snap: Matrix_Snapshot) {
fmt.println("Matrix: Reverting to chronomantic snapshot.")
m.energy = snap.energy
m.frequency = snap.frequency
}
main :: proc() {
matrix := Arcane_Matrix{energy = 100, frequency = 432.0}
fmt.printf("Initial State: Energy %d, Freq %.1f\n", matrix.energy, matrix.frequency)
// The Caretaker saves the state
saved_state := create_snapshot(&matrix)
// Something alters the state (a chaotic surge)
matrix.energy = 5000
matrix.frequency = 999.9
fmt.printf("Surge State: Energy %d, Freq %.1f\n", matrix.energy, matrix.frequency)
// Time reversal
restore_snapshot(&matrix, saved_state)
fmt.printf("Restored State: Energy %d, Freq %.1f\n", matrix.energy, matrix.frequency)
}
The Memento
When threading the needle through chaotic ley-storms, an invocation can quickly mutate into an unstable state. The Memento pattern provides chronomantic insurance. By extracting a plain-old-data Matrix_Snapshot struct—a pristine copy of the internal state devoid of behavioral logic—the caretaker can securely store it. Should the matrix corrupt, it is overwritten with the Memento’s data, ensuring rapid temporal reversion.
Runic Tags:
#behavioral
#odin
#state-saving
#undo