I was giving an example with 4 different characters to be sorted. The convenience store
cd is a set of both
d – but
any(cd) still only matches a single character in the context.
You won’t need the
any(b) any(cd) any(a) rule because that is covered with the rule
any(bcd) any(a) > context(2) context(1) rule; then the recursion we implement with
match ensures that the resulting
b a c/d text gets resorted to
a b c/d with
any(bc) any(a) any(d) > context(2) context(1) context(3).
But I did miss a rule in the
swaps 2/3 section:
any(c) any(b) any(d) > context(2) context(1) context(3)
I would love to add a function to the compiler to generate these rules automatically, for example with something like the following hypothetical construct:
group(reorder) defines order
reorder > any(a) any(b) any(c) any(d)
That would expand out to the rules shown above, including the
match rule. I suspect this is insufficient for a comprehensive solution. Would anyone want to take a stab at defining this more completely and specifying how it transforms into a set of rules in order to add it to the compiler? As a compiler-only change, it would be easy to test and would not have runtime impacts.