For the typed/racket version, helpers like these could be needed to ensure type inference works with few annotations. Otherwise, trivial could be used to track types in simple cases, to reduce the annotation burden in the most common cases.
Existing minor features which extend syntax/parse, match or templates:
colon-match by Alexander Knauth and Jens Axel Soegaard adds classes to match which work like syntax/parse's syntax classes, e.g. (match 1 [x:nat #t])
kw-make-struct by Alexander Knauth allows using keywords to indicate field names both for struct instantiation and pattern matching
seq-no-order by Alexander Knauth is the syntax-parse equivalent of list-no-order for match
match-string by Alexander Knauth allows the use of string-append as a match clause
match-count by Sam Tobin Hochstadt is a profiling tool for match, which counts the number of times each clause matches.
mischief/match by Carl Eastlund includes source locations in the error messages if no clause matches the inputs
plai-match-type is a simple match for use with the PLAI learning language
hash-lookup by Jan Dvořák, a simple hash table descructuring expander compatible with Typed Racket
subtemplate (unpackaged for now) by Georges Dupéron automatically derives gensymed identifiers based on unicode subscripts: (syntax-parse stx [(_ (vᵢ …) f) (subtemplate (let ([tmpᵢ vᵢ] …) (f tmpᵢ …)))) will automatically derive some tmpᵢ identifiers, without the need to manually call generate-temporaries.
[auto-syntax-e]() by Georges Dupéron allows using template pattern variables outside of templates (syntax->datum is implicitly applied to them in that case)
xlist by Georges Dupéron allows superscripts to denote number of repetitions in match patterns and type, e.g. (match '(1 2 3 4 5) [(xlist (? number?)³ b²) b]) ; => '(4 5) and (ann '(1 2 a b c) (xList Number* Symbol³))
extensible-parser-specifications by Georges Dupéron is an unstable library for syntax-parse which allows specifying a partial order between elements within ~no-order, and other global constraints
Feature list:
[ ] Unified matching (syntax-parse/match/etc)
[ ] Unified templates (syntax, quasiquote, etc)
[ ] have as much symmetry as possible between matching patterns and templates, so that when pat and templ are syntactically identical, (unified-match v [pat templ]) acts like the identity function (requested by @jsmaniac)
[ ] self-quoting values should therefore be self-matching (same thing for quoted values):
Existing "mainstream" in Racket:
Thoughts by other people on matching / templating libraries:
Existing minor features which extend syntax/parse, match or templates:
(match 1 [x:nat #t])
syntax-parse
equivalent oflist-no-order
for match~parens
,~brackets
and~braces
tosyntax-parse
string-append
as a match clausematch
, which counts the number of times each clause matches.gensym
ed identifiers based on unicode subscripts:(syntax-parse stx [(_ (vᵢ …) f) (subtemplate (let ([tmpᵢ vᵢ] …) (f tmpᵢ …))))
will automatically derive some tmpᵢ identifiers, without the need to manually callgenerate-temporaries
.(match '(1 2 3 4 5) [(xlist (? number?)³ b²) b]) ; => '(4 5)
and(ann '(1 2 a b c) (xList Number* Symbol³))
syntax-parse
which allows specifying a partial order between elements within~no-order
, and other global constraintsFeature list:
pat
andtempl
are syntactically identical,(unified-match v [pat templ])
acts like the identity function (requested by @jsmaniac)If x is a list, then...
…
…
(requested by @jsmaniac) (template (define ,y ( ,x ,x)) …) => (match-define (list y …) (map (λ (xᵢ) ( xᵢ xᵢ) x))