This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-16
Channels
- # babashka (17)
- # calva (35)
- # clerk (31)
- # cljs-dev (3)
- # clojars (1)
- # clojure (16)
- # clojure-europe (4)
- # clojurescript (38)
- # clojutre (2)
- # cursive (8)
- # datomic (16)
- # exercism (5)
- # fulcro (5)
- # gratitude (3)
- # hyperfiddle (55)
- # joyride (1)
- # lsp (40)
- # off-topic (6)
- # portal (64)
- # practicalli (1)
- # reitit (3)
- # releases (1)
- # shadow-cljs (38)
- # sql (1)
- # tools-deps (8)
- # xtdb (9)
is there a lib or an easy way to create "sub zippers" out of clojure.zip zippers? I want to write functions that look for nodes by calling clojure.zip/next
scoped to a sub tree, edit a node, and then be able to zip back up to the larger tree root
my first thought is to create a new zipper out of the location of the sub tree and stash the original root as metadata, but experience tells me that meta data is not preserved in some cases
meta data is pretty safe in clojure. zippers use meta data. just test your transformations for meta data issues. also, there are other tools in clojure for working with trees, zippers are just one option
Off the cuff, what are some of the other Clojure tools for idiomatically working with trees? When I’m not using zippers, I just resort to Scheme-style recursive functions, which are fine — I’m accustomed to them — but feel “out-dated.”
https://github.com/cloojure/tupelo/blob/master/docs/forest.adoc clojure.walk https://clojuredocs.org/clojure.walk/walk https://github.com/redplanetlabs/specter https://github.com/vvvvalvalval/supdate https://github.com/turtlegrammar/faconne (really cool idea, but has some rough edges) pathom
this is what I was remembering re: metadata and zippers https://ask.clojure.org/index.php/10586/should-clojure-zip-preserve-metadata-zipper-that-end-state
zippers work well for my use case. I'm writing a DSL for modifying a tree. so I can write code like
(-> config-json ; json read from file
(zipper) ; create zipper
(profile "Default profile") ; find the default profile
(device [1452 834]) ; find device <vendor ID, product ID> inside of profile
(remap "a" "z") ; remap key "a" to "z" for device in profile
(to-json)) ; zip up to the top root and convert to json
Maybe you can use my lib zippo: https://github.com/igrishaev/zippo
it has the loc-update
function that takes a predicate and a function that gets applied to the location if the predicate matches
The code might look like this:
(-> read-json
(to->zipper)
(zippo/update-loc loc-profile? ...)
(zip/root)
(zippo/update-loc loc-device? ...)
(zip/root))
that does look nice 😄 I think I wrote loc-find
in my project. seems like a missing piece
I think the difference between my pseudo-code and your pseudo-code is that min is meant to scope the update of the key map to the device inside of the default profile