Transformation by Patterns
Matching and substitution can be combined to transform an input from a pattern-pair: a list of input pattern and output pattern.
(defun transform (pattern-pair input)
(let (bindings)
(if (setq bindings
(match (first pattern-pair) input))
(sublis bindings (second pattern-pair))) ))
>(transform '( (- ?x (- ?y)) (+ ?x ?y) )
'(- z (- (* u v))) )
(+ Z (* U V))
>(transform '((- (+ ?x ?y) (+ ?z ?y))
(- ?x ?z))
'(- (+ (age tom) (age mary))
(+ (age bill) (age mary))))
(- (AGE TOM) (AGE BILL))