Pattern matching in Chez Scheme
(match (list 1 2 3)
[_ 123])
; 123(match '(4 . 5)
[`(,x . ,y) (+ x y)])
; 9(match (list 1 2 3)
[`(,x ,@xs) x])
; 1(match (list 1 2 3)
[`(,x ,@xs) xs])
; (2 3)(match (list 1 2 3)
[`(,x ,@xs) xs])
; (2 3)(match 7
[(x (add1 x) y) (cons x y)])
; (7 . 8)(match (list 1 2 3 4)
[`(2 ,@_) 'huey]
[(x (even? (length x)) #t) 'dewey]
[`(,_ ,(x (even? x) #t)) 'louie])
; dewey💡 View patterns can be used to deconstruct types that are not natively supported like record types and hash tables.