Skip to content

Instantly share code, notes, and snippets.

@wobh
Last active January 25, 2018 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wobh/f6252864ef761570150cdc62176e7c41 to your computer and use it in GitHub Desktop.
Save wobh/f6252864ef761570150cdc62176e7c41 to your computer and use it in GitHub Desktop.
A little game...
;;; History
(defun make-history ()
(let (history)
(lambda (&optional event)
(when (and event
(not (equalp event (first history))))
(push event history))
(first history))))
(defun happen (history event)
(funcall history event))
(defun latest (history)
(funcall history))
;;; Memory
(defun make-memory ()
(let (memory)
(lambda (&optional history)
(when history
(push (latest history) memory))
memory)))
(defun record (memory history)
(funcall memory history))
(defun recall (memory)
(funcall memory))
;;; Experiences
(let ((h (make-history))
(m (make-memory)))
(happen h 1)
(happen h 1)
(record m h)
(happen h 2)
(happen h 1)
(record m h)
(values (latest h)
(recall m)))
(let ((h (make-history))
(m1 (make-memory))
(m2 (make-memory)))
(happen h 1)
(record m1 h)
(happen h 1)
(record m2 h)
(happen h 2)
(record m2 h)
(happen h 1)
(record m1 h)
(values (latest h)
(recall m1)
(recall m2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment