Equality vs. Matching


(define (equal? x y)
  (if (pair? x)
      (and (pair? y)
           (equal? (car x) (car y))
           (equal? (cdr x) (cdr y)))
      (eqv? x y)) )


(define (match? pat inp)
  (let ((bindings '()))

(define (matchb pat inp) (if (pair? pat) (and (pair? inp) (matchb (car pat) (car inp)) (matchb (cdr pat) (cdr inp))) (if (var? pat) (let ((pair (assq pat bindings))) (if pair (equal? inp (cdr pair)) (set! bindings (cons (cons pat inp) bindings)))) (eqv? pat inp))))

(and (matchb pat inp) bindings) ))

Contents    Page-10    Prev    Next    Page+10    Index