This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-04
Channels
- # announcements (123)
- # asami (1)
- # babashka (50)
- # beginners (49)
- # biff (21)
- # calva (48)
- # cider (6)
- # clj-yaml (8)
- # cljsrn (2)
- # clojure (9)
- # clojure-conj (1)
- # clojure-indonesia (1)
- # clojure-losangeles (1)
- # clojure-uk (18)
- # clojurescript (21)
- # data-science (19)
- # datahike (13)
- # events (1)
- # fulcro (1)
- # honeysql (4)
- # hyperfiddle (40)
- # improve-getting-started (3)
- # inf-clojure (1)
- # malli (6)
- # off-topic (45)
- # releases (3)
- # rewrite-clj (14)
- # scittle (1)
- # shadow-cljs (57)
- # tools-deps (1)
- # vim (13)
- # xtdb (14)
Is there a common pattern for tracking namespaces to handle auto-resolving keywords, symbols, and prefixed maps?
@nbtheduke There are options you can provide to sexpr
how to render those, but there isn't any logic to parse ns forms and track ns state.
In edamame that would be done like this:
(require '[clojure.test :as t])
(e/parse-string "::t/foo" {:auto-resolve (fn [x] (if (= :current x) *ns* (get (ns-aliases *ns*) x)))})
:clojure.test/foo
It could maybe be useful to have something like:
(def x (rewrite.namespace/parse-ns-form ns-form-node)) ;; static ns form parsing, no evaluation in the host
whose result you could pass to (sexpr ... {:... x})
@nbtheduke Actually, in grasp, I abuse SCI to emulate the ns state
So you create a context with SCI, then evaluate those namespace forms in the SCI context, so it won't pollute the host
and then you can query the SCI context what aliases there are in the "current" namespace, etc
That’s clever. I’m using edamame right now with the rudimentary ns handling you suggested a while back but thinking of switching back to rewrite-clj cuz I need the zipper api for a feature I’m planning.
I’ll look at how grasp does it, maybe I can rely on sci too
I'll see if I can put something together which is both useful for rewrite-clj and edamame since this is a problem that comes up now and then
That’s kind and helpful of you, thanks
@nbtheduke Here is how I would approach it: https://github.com/borkdude/ns-parser/blob/main/test/borkdude/ns_parser_test.cljc
@nbtheduke Here is how I would approach it: https://github.com/borkdude/ns-parser/blob/main/test/borkdude/ns_parser_test.cljc