2.1.3. Negative Pattern

[Tip]Description

Negative patterns define negative constraints in a pattern body: if a negative pattern can be matched then the match of the container pattern fails.

[Important]Syntax
NegativePatternAST ::= neg PatternCompositionAST
// See also: PatternBodyContentDefAST

A negative pattern is composed of the neg keyword and a pattern definition or pattern composition.

[Note]Semantics

Negative patterns typically search for some prohibited context of the partial match of the container (positive) pattern. If a match is found for the negative pattern, then the match of the container pattern is invalidated.

When a pattern has multiple negative subpatterns, a successful matching of any of its subpatterns invalidates the container pattern.

When a negative pattern itself has an embedded negative subpattern (i.e. negation of negation) then the matching of the subpattern may invalidate the matching of the negative pattern itself, thus the original (positive) container pattern is not invalidated.

Note that when a match is found for a negative pattern, no assignment of pattern variables is passed back to its container pattern.

Defined In:  pattern body