8000 GitHub - qzivli/match: A pattern matching library for Scheme.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

qzivli/match

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

match

A pattern matching library for Scheme.

This program was originally designed and implemented by Dan Friedman. It was redesigned and implemented by Erik Hilsdale; some improvements were suggested by Steve Ganz. Additional modifications were made by Kent Dybvig.

Example

(import (rename (edu indiana match)
                (guard ?)))

(define (tree-sum expr)
  (match expr
    [,x (? (number? x)) x]
    [(,e1 ,e2)
     (let ([v1 (tree-sum e1)]
           [v2 (tree-sum e2)])
       (+ v1 v2))]))

(tree-sum '(1 2))
(tree-sum '(1 (2 3)))
(tree-sum '((1 2) 3))
(tree-sum '((1 2) (3 4)))
(tree-sum '((1 2) (3 (4 5))))

#;(tree-sum '((1 2) (3 (4 #\5))))  ; error

(match '(1 2 1 2 1)
  [(,a ,b ,a ,b ,a) (? (number? a) (number? b)) (+ a b)])  ; 3

(match '((1 2 3) 5 (1 2 3))
  [((,a ...) ,b (,a ...)) `(,a ... ,b)])  ; (1 2 3 5) or ((1 2 3) ... 5) ?

(parameterize ([match-equality-test (lambda (x y) (equal? x (reverse y)))])
  (match '((1 2 3) (3 2 1))
    [(,a ,a) 'yes]
    [,oops 'no]))  ; yes

About

A pattern matching library for Scheme.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0