Skip to content

Commit

Permalink
Tighter source code is a bit less daunting to read (and fits on the p…
Browse files Browse the repository at this point in the history
…age).
  • Loading branch information
axch committed May 23, 2013
1 parent 182a232 commit 2cfb880
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions patterns.scm
Original file line number Diff line number Diff line change
Expand Up @@ -263,41 +263,32 @@
,(last-list-submatcher (car (last-pair pattern)))))))

(new-pattern-syntax! match:list? list-pattern->combinators)


;;;; Making toplevel matchers out of patterns

(define (matcher pattern)
(first-dictionary (match:->combinators pattern)))

(define (first-dictionary matcher)
(lambda (datum)
(matcher
datum '()
(lambda (dict)
(dictionary->alist dict)))))
(define ((first-dictionary matcher) datum)
(matcher datum '() dictionary->alist))

(define (for-each-matcher pattern)
(for-each-dictionary (match:->combinators pattern)))

(define (for-each-dictionary matcher)
(lambda (datum f)
(matcher
datum '()
(lambda (dict)
(f (dictionary->alist dict))
#f))))
(define ((for-each-dictionary matcher) datum f)
(matcher datum '()
(lambda (dict)
(f (dictionary->alist dict))
#f)))

(define (all-results-matcher pattern)
(all-dictionaries (match:->combinators pattern)))

(define (all-dictionaries matcher)
(lambda (datum)
(let ((results '()))
((for-each-dictionary matcher)
datum
(lambda (dict)
(set! results (cons dict results))))
(reverse results))))
(define ((all-dictionaries matcher) datum)
(let ((results '()))
((for-each-dictionary matcher) datum
(lambda (dict) (set! results (cons dict results))))
(reverse results)))

#|
((match:->combinators '(a ((? b) 2 3) 1 c))
Expand Down

0 comments on commit 2cfb880

Please sign in to comment.