rewrite-clj

zimablue 2023-07-23T15:46:44.276639Z

What would be the best way to add data to the rewrite-clj zipper tree (eg. a flag per-node)?

borkdude 2023-07-23T15:56:19.186769Z

Just use assoc?

zimablue 2023-07-23T16:00:28.667979Z

Will the zipper then maintain all that information "correctly" though ? At the bottom there must be operations constructing nodes, this will only work if they're doing a merge or something?

borkdude 2023-07-23T16:19:20.199259Z

don't know about zipper tree

borkdude 2023-07-23T16:20:17.329869Z

why use zippers in this case and not just postwalk the rewrite-clj nodes?

lread 2023-07-23T16:26:30.483539Z

@zimablue if you maybe describe your end goal, i.e. why you feel you need to flag, then maybe we could come up with more ideas. I tend to reach for the zip API, @borkdude tends to walk the nodes directly.

zimablue 2023-07-23T16:34:32.613739Z

Basically I was writing a specialized edn editor (all the way back to formatted text), so theres extra state, and I want it to be "stable" under moving nodes, deleting them etc. Rewrite-clj helps me map changes in edn back to changes in (a whitespace-preserving string), but I want my UI state tagged back and stable too. One way I thought was to annotate each node with an ID, then I have two relationship (str->edn) (edn->id) and it's all good, but that will only work if rewrite-clj is happy to maintain e,tea I formation per zipper node

zimablue 2023-07-23T16:35:12.570589Z

I could also try not using the zipper, I haven't thought it through, I don't think I need to accumulate multiple changes so that efficiency element of zippers is irrelevant

zimablue 2023-07-23T16:36:40.912349Z

*extra information

lread 2023-07-23T16:46:10.146859Z

I have some time later today to play around. I can't remember if assoc on a node would be problematic when using the zip api.

zimablue 2023-07-23T16:46:54.661009Z

A concrete example: I have an edn list of strings, in my app runtime that corresponds to a UI component for each string, with state like text-cursor, I perform an operation like deleting one of the strings, now those strings all have different indexes in their parent list, but on my rerender pass I need to tie back to component state per-string the paths are broken so I need IDs

zimablue 2023-07-23T16:47:16.448449Z

Please don't, I thought someone might just know the answer I'd hate for someone to spend time on it

zimablue 2023-07-23T16:47:33.183279Z

I can just test it / read the code if noone knows offhand

lread 2023-07-23T16:55:31.363529Z

Happy to try to help if you remain stuck. If you get unstuck, please do share what you came up with so we can all learn from your experience.