Skip to content

bjornkihlberg/chezscheme-match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

chezscheme-match

Pattern matching in Chez Scheme


library (match)

syntax match

Examples

Wildcard matching

(match (list 1 2 3)
  [_ 123])
; 123

Pair deconstruction

(match '(4 . 5)
  [`(,x . ,y) (+ x y)])
; 9

List deconstruction

(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)

View patterns

(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.

About

Pattern matching in Chez Scheme

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published