Matching and Substitution

Matching and substitution can be combined to transform an input from a pattern-pair: a list of matching pattern and output pattern.


(defun transf (pattern-list input)
  (let ((bindings (match
                   (first pattern-list) input))
        (test (third pattern-list)))
    (if (and bindings
             (or (null test)
                 (eval (sublisq bindings test))))
        (progn
          (dolist (var (fourth pattern-list))
            (push (cons (car var)
                        (eval (sublisq bindings
                                     (cadr var))))
                  bindings) )     
          (sublis bindings (second pattern-list)))
        'match-failure) ))

Contents    Page-10    Prev    Next    Page+10    Index