Skip to content

Commit

Permalink
Try-rules is only used by pattern dispatch. Since the operators never
Browse files Browse the repository at this point in the history
backtrack, try-rules doesn't need to deal with success continuations.
  • Loading branch information
axch committed May 23, 2013
1 parent 5bbd93d commit b3998a4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pattern-dispatch.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,23 @@

(define (make-pattern-operator rules)
(define (operator self . arguments)
(define (succeed value fail) value)
(define (fail)
(error "No applicable operations" self arguments))
(try-rules arguments (reverse (entity-extra self)) succeed fail))
(try-rules arguments (reverse (entity-extra self)) fail))
(make-entity operator (reverse rules)))

(define (pattern-dispatch . rules)
(make-pattern-operator rules))

(define (try-rules data rules succeed fail)
(define (try-rules data rules fail)
(let ((token (list 'fail)))
(let per-rule ((rules rules))
(if (null? rules)
(fail)
(let ((answer ((car rules) data token)))
(if (eq? answer token)
(per-rule (cdr rules))
(succeed answer (lambda () (per-rule (cdr rules))))))))))
answer))))))

(define (attach-rule! operator rule)
(set-entity-extra! operator
Expand Down

0 comments on commit b3998a4

Please sign in to comment.