The syntax we have defined for patterns has two virtues: first, the syntax is very general, so

Question:

The syntax we have defined for patterns has two virtues: first, the syntax is very general, so it is easy to extend. Second, the syntax can be easily manipulated by pat - ma tc h. However, there is one drawback: the syntax is a little verbose, and some may find it ugly. Compare the following two patterns:

Many readers find the second pattern easier to understand at a glance. We cohld change pat -match to allow for patterns of the form ?x*, but that would mean pat-match would have a lot more work to do on every match. An alternative is to leave pat -match as is, but define another level of syntax for use by human readers only. That is, a programmer could type the second expression above, and have it translated into the first, which would then be processed by pat -match.

In other words, we will define a facility to define a kind of pattern-matcwng macro that will be expanded the first time the pattern is seen. It is better to do this expansion once than to complicate pat -match and in effect do the expansion every time a pattern is used. (Of course, if a pattern is only used once, then there is no advantage. But in most programs, each pattern will be used again and again.)

We need to define two functions: one to define pattern-matching macros, and another to expand patterns that may contain these macros. We will only allow symbols to be macros, so it is reasonable to store the expansions on each symbol's property list:

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: