This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-19
Channels
- # announcements (7)
- # aws (4)
- # aws-lambda (1)
- # babashka (19)
- # beginners (60)
- # calva (9)
- # chlorine-clover (3)
- # cider (15)
- # clj-kondo (17)
- # clojure (34)
- # clojure-czech (1)
- # clojure-europe (96)
- # clojure-nl (2)
- # clojure-uk (46)
- # clojurescript (20)
- # css (4)
- # cursive (58)
- # data-science (3)
- # datascript (3)
- # datomic (42)
- # depstar (30)
- # dirac (4)
- # emacs (1)
- # etaoin (5)
- # events (1)
- # figwheel-main (30)
- # fulcro (6)
- # helix (9)
- # jobs (1)
- # lumo (3)
- # malli (27)
- # off-topic (15)
- # pathom (11)
- # programming-beginners (6)
- # reitit (6)
- # rewrite-clj (11)
- # shadow-cljs (14)
- # sql (1)
- # tools-deps (18)
- # utah-clojurians (3)
hey friends
i'm working on a card game, and i have files with the card effect definitions. i want to fundamentally change how the effect definitions are structured by code-walking and making the changes and then saving the file at the end, but i'm struggling to figure out how to traverse the nodes rewrite-clj gives back
for example, here's a simple card definition:
(defcard "15 Minutes"
{:abilities [{:cost [:click 1]
:msg "shuffle 15 Minutes into R&D"
:label "Shuffle 15 Minutes into R&D"
:effect (effect (move :corp card :deck nil)
(shuffle! :corp :deck)
(update-all-agenda-points))}]
:flags {:has-abilities-when-stolen true}})
i parse the file with (def agendas (z/of-file "src/clj/game/cards/agendas.clj"))
, and then call (z/find-next-value agendas z/next 'defcard)
to move to the defcard
node.
is there a better way of saying (-> (z/find-next-value agendas z/next 'defcard) z/next z/next (z/find-value z/next :abilities) z/right)
to process the map inside the :abilities
vector?
Hi @nbtheduke. I guess you could skip the first find, that is if you don’t need it for some other reason.
(-> agendas
(z/find-next-value z/next :abilities)
z/right)
Would bring you to your :abilities
vector.thank you!
what if i wanted to look at every map literal in the whole file?
@nbtheduke You could iterate through every form in the file using z/next
and check every time if it's a map or not
interesting, okay
@nbtheduke This is also what I do in carve where I remove nodes by looking at the location given a list of locations: https://github.com/borkdude/carve/blob/8e9a29b9b985a89ce0aa0b7f4117e072a07bed44/src/carve/impl.clj#L88