Skip to content

Instantly share code, notes, and snippets.

@favila
Created January 14, 2022 17:28
Show Gist options
  • Save favila/1adac2b1adc61a856a081263d0484176 to your computer and use it in GitHub Desktop.
Save favila/1adac2b1adc61a856a081263d0484176 to your computer and use it in GitHub Desktop.
clojure datafy and nav to explore an open-ended state space
(defn nav-> [x p]
(nav x p (get x p)))
(defn array-game-inc [x k v]
(with-meta
(assoc x k (inc v))
(meta x)))
(defn array-game []
(with-meta
[0 0 0 0]
{`clojure.core.protocols/datafy #'identity
`clojure.core.protocols/nav #'array-game-inc}))
(-> (array-game) ;[0 0 0 0]
(nav-> 0) ;[1 0 0 0]
datafy
(nav-> 0) ;[2 0 0 0]
datafy
(nav-> 0) ;[3 0 0 0]
datafy
(nav-> 1) ;[3 1 0 0]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment