Skip to content

Commit

Permalink
A more compact set of examples is more useful here; and they fit on t…
Browse files Browse the repository at this point in the history
…he page.
  • Loading branch information
axch committed May 23, 2013
1 parent 2cfb880 commit 2ac9f38
Showing 1 changed file with 10 additions and 37 deletions.
47 changes: 10 additions & 37 deletions patterns.scm
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@

(new-pattern-syntax! match:segment?
(lambda (pattern) (match:segment (match:variable-name pattern))))


;; Every other list is a list matcher
(define (match:list? pattern)
(and (list? pattern)
(or (null? pattern)
(not (memq (car pattern) '(? ??))))))


;;; list-pattern->combinators is complicated because it detects the
;;; last submatcher in the pattern and, if it's a segment variable,
;;; arranges for it to avoid its search.
Expand Down Expand Up @@ -289,44 +289,17 @@
((for-each-dictionary matcher) datum
(lambda (dict) (set! results (cons dict results))))
(reverse results)))

#|
((match:->combinators '(a ((? b) 2 3) 1 c))
'(a (1 2 3) 1 c)
'()
(lambda (x) `(succeed ,x)))
;Value: (succeed ((b 1)))

((match:->combinators '(a ((? b) 2 3) (? b) c))
'(a (1 2 3) 2 c)
'()
(lambda (x) `(succeed ,x)))
;Value: #f

((match:->combinators '(a ((? b) 2 3) (? b) c))
'(a (1 2 3) 1 c)
'()
(lambda (x) `(succeed ,x)))
;Value: (succeed ((b 1)))


((match:->combinators '(a (?? x) (?? y) (?? x) c))
'(a b b b b b b c)
'()
(lambda (x)
(pp `(succeed ,x))
#f))
(succeed ((y (b b b b b b)) (x ())))
(succeed ((y (b b b b)) (x (b))))
(succeed ((y (b b)) (x (b b))))
(succeed ((y ()) (x (b b b))))
;Value: #f

((matcher '(a ((? b) 2 3) (? b) c))
'(a (1 2 3) 1 c))
;Value: ((b 1))
|#

;Value: ((b . 1))

(pp ((all-results-matcher '(a (?? x) (?? y) (?? x) c))
'(a b b b b b b c)))
(((y . (b b b b b b)) (x . ()))
((y . (b b b b)) (x . (b)))
((y . (b b)) (x . (b b)))
((y . ()) (x . (b b b)))) |#
;;; Nice pattern inspection procedure that will be used by the
;;; pattern-directed invocation system.

Expand Down

0 comments on commit 2ac9f38

Please sign in to comment.