The Command (Racket)
Encapsulating a spell invocation as an object, allowing for delayed or logged casting.
✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Command
ARCANUM SCHOOL: Enchantment // Runes
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// RACKET PATTERN //
#lang racket
(struct command (execute undo))
(define (make-teleport-cmd x y)
(let ([prev-x 0] [prev-y 0])
(command
(λ ()
(set! prev-x x)
(set! prev-y y)
(printf "Teleported to ~a, ~a\n" x y))
(λ ()
(printf "Reversed teleport. Back to ~a, ~a\n" prev-x prev-y)))))
(define tp (make-teleport-cmd 100 200))
((command-execute tp))
((command-undo tp))
The Command
The Command pattern crystalizes an action into a wieldable artifact. By storing both the execute and undo thunks within a structure, Mages can defer the casting of a spell, pass it to an Invoker, or even reverse time itself by triggering the undo sequence. Parenthetical power mapped to intent.
Runic Tags:
#racket
#behavioral
#command
#macro-metamagic