1. Review Section 2.2 on list primitives and S-expression literals,
and say what is the value of each of the expressions below.
If a run-time error would occur, please explain why.
````
(car '(a b 1 2))
(cdr '(a b 1 2))
(= 'a 'b)
(= '(a b) '(a b))
````
To write your answers, use S-expression literals.
2. Review the first few pages of section 2.3, through the end of
section 2.3.2. Which of the following is true for every *list*
`xs`? Why?
````
(= (reverse (reverse xs)) xs)
(equal? (reverse (reverse xs)) xs)
````
3. Read section 2.3.2, then please explain in your own words the difference
between `simple-reverse` and `reverse`.
4. Review the first part of section 2.4, up to 2.4.4, and ~~write~~
discover a new algebraic law that applies
to some combination of `append` and `length`. ~~Your law should
be~~ Write your law in the style of
section 2.4.4. Like the other list laws in that section, your law
must mention a variable `xs`, which must be allowed to be any
arbitrary list.
5. Review section 2.4.5 and demonstrate the proper form for a
calculational proof by writing a one-step proof that `(+` $e$ `0)`
equals $e$.
6. Imagine you are tasked with translating the following C function
into $\mu$Scheme:
````
bool parity(int m) {
int half_m = m / 2;
int other_half = m - half_m;
return half_m == other_half;
}
````
Review section 2.5, and answer these questions:
(a) Is it sensible to use `let`? Why or why not?
(b) Is it sensible to use `let*`? Why or why not?
(c) Is it sensible to use `letrec`? Why or why not?
7. The `cons` cell is used for more than just lists---it's the basic
element of every $\mu$Scheme data structure. Almost like the
assembly language of functional programming. What a `cons` cell
means depends on how it is used and what is the programmer's
intent.
Review section 2.6, especially the definitions of *SEXP* and
*LIST*$(\cdots)$, and answer these questions:
(a) Is the value `(cons 3 4)` a member of *SEXP*? Why or why not?
(b) Given that 3 and 4 are members of set *NUM*, is the value
`(cons 3 4)` a member of set *LIST(NUM)*? Why or why not?
Your answers should appeal to the numbered equations or named
proof rules at the beginning of section 2.6.