Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Syntax and reader by

Say I have an edn file like this:

{:name :some-name
:some-key #my/data-reader-fn [1 2 3]}

Now say I want to change the content of :name programatically.

If I read the edn file, the data-reader-fn will be applied, and so if I want to write my changes to the edn file, :some-key will be changed too.

Is there a workaround for this problem?

1 Answer

+5 votes
by
selected by
 
Best answer

Option 1 - don't use your reader function and/or install an alternate. Binding default-data-reader-fn to tagged-literal is a valid "pass-through" workaround. See https://insideclojure.org/2018/06/21/tagged-literal/ for a longer writeup on that.

Option 2 - supply a custom print function for whatever object data-reader-fn reads as to have it print with the same tagged literal. You may need to supply both a print-method and a print-dup multimethod impl (it's keyed on class).

by
Brilliant. edn/read accepts a :default key in its opts, passing tagged-literal to it worked perfectly! Thank you very much!
...