The goals of this assignment are to refresh your skills with Scheme, and to serve as a diagnostic. Most of the subsequent assignments in this course will require a solid foundation in Scheme programming, such as is required to complete the problems below. If you have trouble with this assignment, you will likely have trouble in the rest of the course as well.
Implement a simple Scheme program to count the number of atoms
in an arbitrary Scheme expression. An atom is anything which does not
satisfy the
In this problem, you will extend a simple list matching program.
The matcher takes two lists as input, one of which contains variables
(the pattern) and one of which does not (the data). The matcher returns
a list of bindings that would make the pattern match the data.
Variables are represented as a list the first element of which is
(match '(a (? x) b c) '(a d b c)) ==> (bindings (x d))
The return value is a list of which the car is "bindings" and the cdr is a list of lists, where the first element of each list is the name of the variable and the second is the value to which it should be bound. E.g.
Matches can appear at any level, and a successful match returns an empty list of bindings. An unsuccessful match returns #f. The code also supports unnamed variables that simply match without returning assignments and are not required to match the same values.
Extend the matcher to allow a new class of variables which match can match sublists of data rather than only atoms. The binding value MUST be a list - even if it is the null list. You should produce SOME binding for each of these variables, though the assignment may not be unique. The solution need not be efficient. (In fact, the straightforward solution is likely to be quite INefficient.)
Please ignore the case where the pattern is a singleton variable rather than a list. Also ignore the error case in which both sublist and atom variables have the same name - you don't need to do the error checking.
The basic code can be found here .