clojure.walk/walk doesn't preserve metadata on lists/seqs

Description

Example:

Patches:

  • clj-2568-1 checks if the form was a clojure.lang.IObj and if the result transformed with f is also a clojure.lang.IObj. If so, it copies the metadata from original to transformed.

  • clj-2568-2 inlines the cond form of the extra var/function that was introduced

  • clj-2568-3 allows the function arg f in postwalk to update the restored metadata (attach additional data, remove metadata, etc).

There might be an optimization possible in the anonymous function used in clj-2568-3 which can be implemented once there is agreement on the chosen direction.

Environment

None

Activity

Show:
Michiel Borkent
May 31, 2020, 7:07 PM

clj-2568-2 inlines the cond form.

Alex Miller
May 31, 2020, 7:54 PM

Something to consider is whether existing code modifies coll metadata during walk and will thus be broken by this change.

Michiel Borkent
June 1, 2020, 11:37 AM
Edited

Uploaded patch clj-2568-3 where function f gets control over the final metadata. It sees the restored metadata and can then make decisions as to leave it there, update it, remove it, etc.

I had to update the test in readers.cljc since it was accidentally testing the non-preservation of metadata by comparing two nil items.

Yehonathan Sharvit
June 9, 2020, 6:21 AM

Notice that this bug also impact other functions in clojure.walk namespace (e.g clojure.walk/keywordize-keys)
Should we create another ticket for that?

Michiel Borkent
August 6, 2020, 8:01 PM

: patch CLJS-2568-3 should also fix other usages of clojure.walk:

Assignee

Unassigned

Reporter

Dominic Monroe

Labels

None

Approval

None

Patch

Code and Test

Priority

Major
Configure