This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-06
Channels
- # adventofcode (10)
- # ai (2)
- # aleph (2)
- # announcements (21)
- # beginners (25)
- # calva (7)
- # cider (19)
- # clj-kondo (28)
- # clj-on-windows (3)
- # cljdoc (6)
- # clojure (80)
- # clojure-dev (15)
- # clojure-europe (29)
- # clojure-italy (3)
- # clojure-nl (37)
- # clojure-uk (4)
- # clojurescript (3)
- # cloverage (1)
- # conjure (6)
- # core-async (2)
- # cursive (17)
- # datalevin (9)
- # datomic (7)
- # deps-new (23)
- # emacs (4)
- # figwheel-main (6)
- # fulcro (6)
- # honeysql (19)
- # improve-getting-started (4)
- # inf-clojure (2)
- # introduce-yourself (5)
- # jobs (1)
- # leiningen (6)
- # lsp (73)
- # malli (1)
- # nrepl (2)
- # off-topic (37)
- # polylith (9)
- # quil (2)
- # reitit (16)
- # releases (2)
- # remote-jobs (6)
- # rewrite-clj (38)
- # shadow-cljs (1)
- # tools-build (1)
So in relation to the problem I described a few days ago, I wrote a function which attempts to determine whether some zloc is in the key position of a map. But I think it only works for the first map entry
(defn map-key?
[zloc]
(and
(zip/map? (zip/up zloc))
(zip/leftmost? zloc)))
Anyone know how this could be written to match a key in any map entry?@cddr how I approached this in rewrite-edn: I just treated every nth element as a key and every n+1th element as a value
@cddr if you need to, you might also want to consider accounting for any #_
that might be present. Example {:a #_ ignored-thing 1}
Oh fortunately I don’t think I’ll need to worry about that but thanks for the headsup
was wondering if anybody could help here, when I do this
(z/sexpr (z/of-string "{:db.sql/connection #profile\n {:prod {:jdbc-url #env JDBC_URL}}}"))
I end up with
#:db.sql{:connection (read-string "#profile\n{:prod {:jdbc-url #env JDBC_URL}}")}
is there a way to roundtrip this properly?@yogthos you can do this by (binding [*print-namespace-maps* false] ...)
, forgive me the bolded font, it's supposed to be earmuffed.
hmm no dice
(binding [*print-namespace-maps* false]
(z/sexpr (z/of-string "{:db.sql/connection #profile\n {:prod {:jdbc-url #env JDBC_URL}}}")))
it's this bit that's causing trouble (read-string "#profile\n{:prod {:jdbc-url #env JDBC_URL}}")
I think this is because you cannot convert #profile ..."
to an s-expression without letting rewrite-clj know how to resolve that reader tag
I just need to inject a piece of edn into a file, so yeah maybe I'm barking up a wrong tree here
I use a zipper to find the target location, and then do this
(defn edn-merge-value [value]
(fn [node]
(if-let [inside-map (z/down node)]
(-> inside-map
(z/rightmost)
(zipper-insert-kw-pairs (z/down value)))
(z/replace node (z/node (format-zloc value))))))