Fork me on GitHub
#meander
<
2020-10-16
>
schmee14:10:53

I finally have a real use-case for Meander! 🎉

schmee14:10:10

I’ve already managed to do what I want, which is great, but is there any way to remove the duplication in this rewrite?

schmee14:10:12

(m*/rewrite
    [:and [!as ...]] [:and . !as ...]
    [:or [!as ...]] [:or . !as ...]))

schmee14:10:01

basically, :and and :or are both operators, so the pattern should be, “if the first element is an operator…”

Jimmy Miller14:10:27

Do you have a defined set of operators you want to match on?

schmee14:10:12

yes, the set of operators is fixed!

Jimmy Miller15:10:44

On my phone, but you should be able to do (m/pred #{:and :or} ?op)

schmee15:10:38

worked like a charm, thanks! 🚀

schmee15:10:40

follow-up: is there any way to bind this pattern to a name so I can re-use it in all the rules without re-typing it?

schmee15:10:07

I tried m/let but at least on my first attempt it didn’t do the trick