Patterns

Marker terms build patterns out of ordinary BasicSymbolic expressions; VarSpecs in the vars map of compile_pattern attach predicates, bounds, and defaults.

Marker terms

MatchMaker.slot — Function
slot(x)

Create a slot marker term wrapping the symbolic variable x — matches exactly one subject term. x may be a Sym (wrapped as-is) or a Symbol (a fresh Sym is created; type/shape keywords apply). The inner Sym's symtype is the type constraint.

source
MatchMaker.segment — Function
segment(x)

Create a segment marker term wrapping x: matches a contiguous run (free/associative heads) or a sub-multiset (commutative/AC heads) of an argument list. See slot.

source
MatchMaker.optional — Function
optional(x)

Create an optional marker term wrapping x: a slot occurrence that may instead bind the variable's VarSpec.Slot.default (the default lives in the spec, not in the tree). See slot.

source

Variable specs

MatchMaker.VarSpec — Module
VarSpec

Per-variable spec record owned by a Matcher (DESIGN.md §3.1):

  • VarSpec.Slot(predicate, default) — default === nothing means required.
  • VarSpec.Segment(predicate, sequence_predicate, min, max) — min/max bound capture cardinality (0/typemax(Int) = unbounded).
source
MatchMaker.slotspec — Function
slotspec(; ...) -> MatchMaker.VarSpec.var"typeof(VarSpec)"
slotspec(
    predicate;
    default
) -> MatchMaker.VarSpec.var"typeof(VarSpec)"

Build a slot VarSpec for the vars map of compile_pattern. A non-symbolic default is wrapped in Const{SymReal}.

source
MatchMaker.segmentspec — Function
segmentspec(
;
    ...
) -> MatchMaker.VarSpec.var"typeof(VarSpec)"
segmentspec(
    predicate;
    ...
) -> MatchMaker.VarSpec.var"typeof(VarSpec)"
segmentspec(
    predicate,
    sequence_predicate;
    min,
    max
) -> MatchMaker.VarSpec.var"typeof(VarSpec)"

Build a segment VarSpec for the vars map of compile_pattern. 0 <= min <= max is enforced.

Two predicate roles:

  • predicate — applied to each captured element. A failing element rejects any capture containing it: under an ordered head (contiguous runs) the run stops growing entirely; under an unordered head (sub-multisets) only the combinations containing it are rejected.
  • sequence_predicate — applied to the whole captured Vector. Failure only invalidates the current capture; the matcher retries with other lengths/selections, since another collection may satisfy it.

Prefer predicate for per-element checks — it prunes strictly more.

source

Macros

MatchMaker.@slots — Macro
@slots x y::Real f(a) ...

Create slot variables: x = slot(Sym(:x)), y = slot(Sym(:y; type = Real)), f = slot(Sym(:f; type = FnType{Tuple{...},...})) for function-like heads. Parsing is the same as SymbolicUtils.@syms.

source

Marker predicates and accessors

MatchMaker.is_marker_term — Function
is_marker_term(
    x::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{T} where T
) -> Bool

Whether x is a marker term — a Term headed by slot, segment, or optional. Matches the Term variant directly (rather than iscall/operation, which @match over every symbolic variant).

source
MatchMaker.is_marker_op — Function
is_marker_op(op) -> Bool

Whether op is one of the pattern-variable marker functions (slot, segment, optional). Identity comparison only — never allocates.

source
MatchMaker.unwrap_varspec — Function
unwrap_varspec(
    x::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{T} where T
) -> Any

If x is a marker term, return its inner Sym; otherwise return x. Used for key normalization in Substitution (DESIGN.md §5.6).

source
MatchMaker.varsym — Function
varsym(
    x::SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{T} where T
) -> Any

The inner Sym of a marker term. Throws if x is not a marker term.

source