previous | index | next

Exercise 7.35 – An Optimization

Note that the test for exercise 7.35 implements a suggestion made by the textbook authors:
"You can also redesign the program to eliminate matches?, because a pattern matches if there are one or more sets of substitutions that make it match." (p. 201)
You can see the redesign in the redefine-answer-by-pattern-for-test procedure definition in movie-test-utilities.scm. Rather than calling matches?, the procedure checks to see if the list of substitutions returned by substitutions-in-to-match is empty or not.

This makes the overall program far more efficient, because each pattern is processed only once, not twice.

This also means that your new substitutions-in-to-match must return an empty list if the pattern and query do not match.


previous | index | next