Building on Transformation
The pattern matcher in the file patm.lsp has additional
features that are needed for transformations:
- Constant folding and partial evaluation. When certain
functions have constant arguments, the functions are evaluated
as part of the transformation process. Note: such evaluation
must not cause an error; functions that have side-effects
(e.g. printing) should not be evaluated.
- Recursion and repetition. Parts of a complex expression must be
recursively transformed. Sometimes one transformation will expose
an opportunity for constant folding or other transformations.
( (+ ?n (+ ?m ?x)) (+ (+ ?n ?m) ?x) )
where ?m and ?n are numbers,
will cause the input (+ 3 (+ 7 foo)) to be transformed to
(+ (+ 3 7) foo) and then, by constant folding, to
(+ 10 foo) .