3 ms·
Clojure has provided an excellent model for how to do similar operations in a dynamically typed language with pervasive maps & vectors: (update-in player1
by brandonbloom 13y ago
Clojure has provided an excellent model for how to do similar operations in a dynamically typed language with pervasive maps & vectors:
(update-in player1 [:location :x] + 10)
This works especially nicely with the threading macros. Here's some random example I'll make up:
(-> player1
(update-in [:location :x] + 10)
(assoc-in [:inventory 3 :equipped] true))
The general idea is that a tree of associative data structures (which include integer-indexed vectors) can have a path to a location in the tree reified as normal data. Then, you can run any ordinary function on a deep position in the tree without any of the applicative functors machinery.