Fork me on GitHub

Really interesting pattern you have there. I personally, haven't had that use case, so haven't really thought about it. Does it work with multiple of them nested? Might have to play around with it


I wrote it for a very particular use case - "editing" XML


I believe I have one nested use case and I haven't seen a problem. I'll look more deeply into it


I got to thinking that the "edit" use case might deserve a DSL of its own. The DSL would be similar to m/rewrite but every "rule" would need to specify three things:


1. a matching rule - just like the current rewrite LHS. the matching rule is used to capture values to be used later 2. the new value rule. this is similar to rewrite's RHS but a new value rule would only return a value that would be used to replace an existing node in the tree 3. a targeting rule. this is a rule that works similarly to matching rule but is used to locate the position(s) of the new value


Oh, one more difference from rewrite: If no edit rules match, return the original form


I want to keep this alive too. The conversation about editing is important.

👍 2

I will try to write up some code examples this weekend


Picking this back up


I played around with a new pattern match operator that I call edit. I tried getting it to work the way I describe above but I ran into a problem with recursion. I just couldn't find an intuitive way to express how to recurse when then target rule is different than the matching rule


I'm back to believing that the edit use case is best served something like the within syntax. see


The within syntax that I wrote doesn't really follow the spirit of meander so I'm going to play around with a better cultural fit today.


The problem with something like within is that it needs to introduce multiple matching variables each of whose names must match in the match-syntax phase and the subst-syntax phase. I think it would be safer if the pattern matching operator (`rewrite` in this case) provided some context that could be shared between the two macro expansion phases


@markaddleman That looks interesting. You didn’t come across as a snarky either. 🙂

🙏 2

I’ve done this before too but I confess that I hadn’t thought about doing it this way.


This actually makes me think that, among other things, we should be able to use & more than once in sequential types of patterns.

(& ?before <pattern> ,,, & ?after)


that would be convenient


I think it makes sense and would be able to contribute more thoughts provided an example/sketch.


I could play around with some example syntax and post here


Its certainly welcome. 🙂