7.7
Extra Utilities for match
(require match-plus) | package: match-plus |
1 Pattern Matching in Simple Functions
syntax
(define/match* (head-id args) body)
args = match-expr ... | match-expr ... . rest-expr
Allows inline pattern-matching in simple function definitions with behavior similar to
match-lambda**. However, only one match clause may be specified since the match patterns are
inline with the formals definition. This means an error will be raised if pattern-matching fails, but
it is ideal if a function is already contracted in such a way that successful pattern-matching is
guaranteed.
Equivalent to:
(define (head-id args*) (match* (args*) [(args) body]))
where args* is a list of unique identifiers generated corresponding to each arg.
Examples:
> (struct point (x y) #:transparent)
> (define/match* (point-add (point a b) (point c d)) (point (+ a c) (+ b d))) > (point-add (point 5 9) (point -3 2)) (point 2 11)