Hints for Writing shadowed-vars

The shadowed-vars problem is a bit bigger than the usual homework problem, including is-declared?. Like lexical-address, it benefits from you using several different tools you've learned over the semester. You will probably also want to create a helper function or two.

Below are hints to move you in the right direction. Feel free to use any or all of them.

Function Structure

Use structural recursion over the inductive expression type to define the structure of your function. There are four kinds of expression in the core language, so your function will make a four-way choice.

Return Value

(shadowed-vars exp) returns a list. That means all four cases have to return a list.

The Variable Reference Case

There are no variables shadowed in a variable reference, obviously, so that case returns an empty list.

The if Expression Case

In an if expression, there could be shadowed variables in any of the three parts. Use recursive calls to find them, and then append the three results. append is a variable-arity function, so you can combine the three lists with one call.

The Application Case

In an app expression, there could be shadowed variables in the procedure part or in any of the arguments. Find the answer for the procedure part and the answer for the arguments, and then append the results.

You can find the answer for the arguments in one of two ways:

The lambda Case

In a lambda expression, a variable can be shadowed in one of two ways:

Compute these two lists and append the results.

Again, you can find the answer for the lambda's parameters using the map-reduce pattern or by writing a recursive helper function. For this one, you may find the recursive helper function a bit easier to write and understand.