A 'rule' is a combination of a possibly-failing matcher (see emmy.match
), an optional matcher predicate that can introduce NEW bindings, and a consequence function (see emmy.consequence
)
The final rule is a function from a data input to either failure or a successful transformation.
This namespace defines:
Rules are composed from matchers and consequences; these functions are politely aliased into this namespace to make it more self contained.
[[pattern*]] is effectively an alias for [[match/matcher]]; the macro form, [[pattern]], is able to take a pattern with un-quoted forms like ?x
. See [[syntax/compile-pattern]] for details.
NOTE: These should almost certainly live in emmy.match
. Can we alias a macro into this namespace with Potemkin?
The following section defines a small set of basic rules, as well as a series of rule "combinators". These are functions that take one or more rules as inputs and return a new rule.
The next group of rule combinators are designed to accept an expression built out of Clojure data structures and apply the rule in either depth-first or breadth-first fashion.
Term-rewriting systems often declare sets of rules meant to be attempted one after the other, just like [[choice]]; but failure for term-rewriting should return the term with no transformation.