chickadee » matchable » match-lambda

(match-lambda (pat body …) …)syntax
(match-lambda* (pat body …) …)syntax

The match-lambda and match-lambda* forms are convenient combinations of match and lambda, and can be explained as follows:

(match-lambda  (pat body …) …)
  --> (lambda (x) (match x (pat body …) …))

(match-lambda* (pat body …) …)
  --> (lambda x   (match x (pat body) …))

where x is a unique variable.

The match-lambda form is convenient when defining a single argument function that immediately destructures its argument. The match-lambda* form constructs a function that accepts any number of arguments; the patterns of match-lambda* should be lists.

For example, the map procedure can be written as:

(define map
  (match-lambda*
    [(_ ()) '()]
    [(f (x . y)) (cons (f x) (map f y))] ))