A consequence is a function from a binding dictionary (produced by a matcher) to a successful result or a failure. A "rule" (see emmy.pattern.rule
) is built out of a matcher (from emmy.pattern.match
) and a consequence function.
The contract for a "consequence" function is that it can return false
, nil
or [[emmy.pattern.match/failure]] to signal failure. But what if the function wants to succeed with false
or nil
?
Wrapping a return value with [[succeed]] will allow a successful return of false
or nil
; a rule using a consequence function uses [[unwrap]] to retrieve the value before returning it.
A Skeleton is a template of the form that we'd like to return from a consequence function, with emmy.pattern.matching variables like ?x
and ??x
in place of binding map lookups.
[[compile-skeleton]] transforms an expression like
Into a form like the following, meant to be evaluated in an environment where m
is bound to some map of bindings (the user provides this symbol):
See [[compile-skeleton]] for the full set of transformation rules.