Recognition by Matching

Pattern matching can be used to determine whether a function matches a design pattern:


(define pattern
  '(define (?fun tree)
     (if (pair? tree)
         (?combine (?fun (car tree))
                   (?fun (cdr tree)))
         (if (?test? tree) ?trueval ?falseval))))

> (match? pattern '(define (nnums tree) (if (pair? tree) (+ (nnums (car tree)) (nnums (cdr tree))) (if (number? tree) 1 0))) )

((?falseval . 0) (?trueval . 1) (?test? . number?) (?combine . +) (?fun . nnums))

Contents    Page-10    Prev    Next    Page+10    Index