about:pattern-matching
case-match ecase-match if-match when-match
Inspired by the Common Lisp library optima.
The simplest pattern is a constant, such as a number, string or 'expression.
It matches anything that is equal to it.
make-html > (if-match 123 (+ 100 23) true)
it: true
make-html > (var expr '(1 2 3))
it: expr
make-html > (if-match '(1 2 3) expr true)
it: true
The symbol pattern is usually found as a subpattern of a structural pattern.
The symbol names a variable that will be declared and bound when the pattern
matches.
make-html > (var expr '(1 2 3))
it: expr
make-html > (if-match (list a b c) expr "a=${a} b=${b} c=${c}")
it: "a=1 b=2 c=3"
make-html > (if-match (list 1 2 c) expr "c=${c}")
it: "c=3"
Patterns can be combined with and, or and not.
make-html > (if-match (and (satisfies integer?) (satisfies odd?)) "a" true)
it: null
make-html > (if-match (and (satisfies integer?) (satisfies odd?)) 123 true)
it: true
make-html > (if-match (and (satisfies integer?) (satisfies odd?) x) 123 x)
it: 123
The property pattern tests one or more properties of a prototype object.
make-html > (var obj (new :name "teun" :city "leiden" :country "netherlands"))
it: obj
make-html > (if-match (property :name "teun" :city "leiden") obj true)
it: true
make-html > (if-match (property :name (type 'string)) obj true)
it: true
make-html > (if-match (property :city (regex "lei") name) obj name)
it: "leiden"
literal-expr
symbol
(and pattern*)
(or pattern*)
(not pattern)
(satisfies predicate-func)
(cons left-pattern right-pattern)
(vector pattern*)
(list pattern*)
(sequence pattern*)
(enumerable pattern*)
(quote expr)
(eq value)
(eql value)
(equal value)
(= value)
(equal-ci value)
(type type-name)
(regex regex-expr)
(property property-pattern*)