Last active
January 25, 2018 03:17
-
-
Save wobh/f6252864ef761570150cdc62176e7c41 to your computer and use it in GitHub Desktop.
A little game...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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