id (excluding the reserved names , …, .., ..k, and ..k for non-negative integers k) or (var id) — matches anything, and binds id to the matching values. If an id is used multiple times within a pattern, the corresponding matches must be the same according to (match-equality-test), except that instances of an id in different or and not sub-patterns are independent. The binding for id is not available in other parts of the same pattern.
I was pleasantly surprised by the way this works.
(define (f xs ys)
(match (list xs ys)
[(list (list a b) (list a c)) 'heads-are-equal]
[(list (list a b) (list c d)) 'heads-are-not-equal]))
> (f (list 1 2) (list 2 3))
'heads-are-not-equal
> (f (list 1 2) (list 1 3))
'heads-are-equal
Yea, it’s like some kind of implicit binding akin to Prolog.
Racket can sometimes be a bit verbose, and I was pointed to this when asking on the #Racket IRC channel how people deal with that. I’m new to pattern matching, but I find it more terse and understandable than multiple ifs and lets, and more flexible than anaphoric macros like aif and awhen.
I was pleasantly surprised by the way this works.
Yea, it’s like some kind of implicit binding akin to Prolog.
Racket can sometimes be a bit verbose, and I was pointed to this when asking on the #Racket IRC channel how people deal with that. I’m new to pattern matching, but I find it more terse and understandable than multiple
ifs andlets, and more flexible than anaphoric macros likeaifandawhen.