rewrite-edn icon indicating copy to clipboard operation
rewrite-edn copied to clipboard

Guidance on working with reader macros

Open martinklepsch opened this issue 2 years ago • 7 comments

Is it in scope for this lib to support transforms involving reader macros? I'm not sure how this would work so totally understand if it's out of scope :)

(require '[borkdude.rewrite-edn :as r])
(def z (r/parse-string "{:data {:foo #profile {:prod 1 :dev 2}}}"))
(r/get-in z [:data :foo]) ;-> <reader-macro: #profile {:prod 1 :dev 2}>
(r/assoc-in z [:data :foo :prod] false) ;-> NPE

martinklepsch avatar Nov 26 '23 14:11 martinklepsch

Show me how you would use get-in with normal EDN that contains a reader macro

borkdude avatar Nov 26 '23 15:11 borkdude

Show me how you would use get-in with normal EDN that contains a reader macro

Yeah I don't really know how that would work either 😅 I was just thinking of transforming aero configs using rewrite-edn so that's where that line of thinking is coming from...

martinklepsch avatar Nov 26 '23 16:11 martinklepsch

I don't know the answer either but would be happy to hear what you came up with :)

borkdude avatar Nov 26 '23 16:11 borkdude

Actually, thinking about this more, couldn't there just be a special way of "entering" the value behind the reader macro? I guess that's possible with rewrite-clj already... 💡 I think I just need dive into rewrite-clj a bit more :)

Feel free to close this :)

martinklepsch avatar Nov 27 '23 22:11 martinklepsch

Yes, I guess we could support that, e.g. (get-in [:foo :bar ?? :prod]) but what would go on the question marks?

borkdude avatar Nov 27 '23 22:11 borkdude

That's the question, isn't it? 😀 Maybe something like this?

(r/get-in [:foo :bar (r/reader-tag 'profile) :prod])

martinklepsch avatar Nov 28 '23 11:11 martinklepsch

I'd be willing to support that

borkdude avatar Nov 28 '23 11:11 borkdude