Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Last active March 31, 2017 18:30
Show Gist options
  • Save lazywithclass/39bb8dde01da04d959ba7f43ffb79c99 to your computer and use it in GitHub Desktop.
Save lazywithclass/39bb8dde01da04d959ba7f43ffb79c99 to your computer and use it in GitHub Desktop.
[RC Diary] Mutating one thing at a time (-61)

[RC Diary] Mutating one thing at a time (-61)

Cerebro

To apply a mutation at a time, be that

  • the same mutation having multiple occurrencies in the same file, or
  • different mutations having each an occurrency in the same file

multiple versions of the same file should be created, with one mutation applied in each, in a different spot.

The most readable and simple approach could be something like this:

  • a ClojureScript function that recursively looks through the AST for a match with a given function
  • if a match is found a mutation is applied to a copy of the AST and returned
  • we then proceed with the original AST, just further down the tree

The problems I see here are:

  • the walking function will quickly go out of sync with the advancement of language syntax
  • I don't see how I could use a JavaScript library for AST traversing and accumulate results

The last problem is the tricky one, because I don't know how to pass a reference of a ClojureScript data structure to a JavaScript module and mutate that referenced object. I think I will go with my own traversal implementation, so I have full control on how I want to collect results and do mutations.

This whole thing took me a day to realise, and I'm still unsure on how to approach details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment