1. Read Sections 2.1 and 2.2 (the first part of the second lesson) in [*Seven Lessons in Program Design*](../design/lessons.pdf). You are tasked with writing a function that consumes a list of numbers: (a) How many cases must you consider? (b) To tell the cases apart, what condition or conditions will you use in `if` expressions? (List one fewer condition than cases.) You are tasked with writing a function that consumes an ordinary S-expression. (c) How many cases must you consider? (d) To tell the cases apart, what condition or conditions will you use in `if` expressions? (List one fewer condition than cases.) _You are ready to write algebraic laws using Scheme data._ 2. In the main textbook, review section 2.2 on values, S-expressions, and primitives, and say what is the value of each of the expressions below. If a run-time error would occur, please say so. (car '(a b 1 2)) (cdr '(a b 1 2)) (= 'a 'b) Write your answers as S-expression literals, like `'(a b c)`, `#t`, or `17`. _You are on your way to being ready for exercises **8** and **C**._ 3. Also in section 2.2, review the printing primitives. Now study the example in code chunk 23c, in which calling primitive `print` causes numbers 4, 5, and 20 to be smushed together. In order to get 4, 5, and 20 each on a line by itself, what primitive should you call instead? 4. In *Programming Languages: Build, Prove, and Compare*, review the first few pages of section 2.3, through the end of section 2.3.2, and also section 2.3.6, which starts on page 106. Which of the following expressions evaluates to `#t` for every *list of ordinary S-expressions* `xs`? (= (reverse (reverse xs)) xs) (equal? (reverse (reverse xs)) xs) (a) Only the first (b) Only the second (c) Both the first and the second (d) None 5. Read the introduction to algebraic laws in the first page of section 2.5, which starts on page 112. Now say under what circumstances the law `(car (cons x xs)) = x` would be considered *valid*: (a) If there is any way to substitute *values* for `x` and `xs` such that the two sides are equal. (b) If there is any way to substitute *expressions* for `x` and `xs` such that the two sides are equal. (c) If no matter what *value* is substituted for `x` and what value is substituted for `xs`, the two sides are equal. (d) If no matter what *expression* is substituted for `x` and what list of expressions is substituted for `xs`, the two sides are equal. _You are now prepared to understand what is being proved in Exercise A._ 6. Algebraic laws are used to express *properties*, not just for program design. Read section 2.3 (another part of the second lesson) in [*Seven Lessons in Program Design*](../design/lessons.pdf), and also the first part of section 2.5 in the main textbook, up to and including section 2.5.5. Now complete the following laws, each of which should represent a valid property: (find x (bind x v rho)) = ... (append xs (append '() ys)) = ... (if p (if p x y) z) = ... _You are now prepared for the algebraic laws in exercises **A** and **C**._ 7. In *Programming Languages: Build, Prove, and Compare*, read the two laws for `append` (which we will call "append-empty" and "append-cons") on page 101, and then study the proof at the bottom of page 117, which shows that `(append (cons x '()) ys)` equals `(cons x ys)`. Now answer this question: how many other *laws* are used in the proof, and what are their names? > Your answer: 8. Read section 2.6, which explains `let` and `let*`. Now answer the questions below: (a) What does the `let` expression in the following program evaluate to? (val x 3) (let ([x 4] [y x]) y) Your answer: (b) What does the `let*` expression in the following program evaluate to? (val x 3) (let* ([x 4] [y x]) y) Your answer: (c) What does the `let` expression in the following program evaluate to? (val x 3) (val y 4) (let ([x y] [y x]) y) Your answer: _You are now ready to program using `let` and `let*`._ 9. Read section 2.4, which starts on page 109. Imagine that $\mu$Scheme is given the following definition: (record 3point [x y z]) This definition puts five functions into the environment ρ. * What are their names? * Which one is the _type predicate_? * Which one is the _constructor_? _You are now mostly ready for exercise **E**._