4 Find "normal forms" for the following---that is, reduce them until no more reductions are possible. As mentioned in the notes, we'll write <code>λx</code> as `\x`. If we ever say "reduce" without qualifications, we mean just "beta-reduce" (as opposed to "(beta + eta)-reduce").
10 5. `(\x (x (\y y))) (\z (z z))`
11 6. `(\x (x x)) (\x (x x))`
12 7. `(\x (x x x)) (\x (x x x))`
18 Recall our definitions of true and false.
20 > **true** is defined to be `\t f. t`
21 > **false** is defined to be `\t f. f`
23 In Racket, these functions can be defined like this:
25 (define true (lambda (t) (lambda (f) t)))
26 (define false (lambda (t) (lambda (f) f)))
28 (Note that they are different from Racket's *primitive* boolean values `#t` and `#f`.)
31 <LI>Define a `neg` operator that negates `true` and `false`.
43 <LI>Define an `or` operator.
45 <LI>Define an `xor` operator. If you haven't seen this term before, here's a truth table:
47 true xor true == false
48 true xor false == true
49 false xor true == true
50 false xor false == false
59 Recall our definitions of ordered triples.
61 > the triple **(**a**,**b**, **c**)** is defined to be `\f. f a b c`
63 To extract the first element of a triple t, you write:
67 Here are some definitions in Racket:
69 (define make-triple (lambda (fst) (lambda (snd) (lambda (trd) (lambda (f) (((f fst) snd) trd))))))
70 (define fst_of_three (lambda (fst) (lambda (snd) (lambda (trd) fst))))
71 (define snd_of_three (lambda (fst) (lambda (snd) (lambda (trd) snd))))
75 (define t (((make-triple 10) 20) 30))
76 (t fst_of_three) ; will evaluate to 10
77 (t snd_of_three) ; will evaluate to 20
79 If you're puzzled by having the triple to the left and the function that
80 operates on it come second, think about why it's being done this way: the pair
81 is a package that takes a function for operating on its elements *as an
82 argument*, and returns *the result of* operating on its elements with that
83 function. In other words, the triple is a higher-order function.
87 <LI>Define the `swap12` function that permutes the elements of a triple. Expected behavior:
89 (define t (((make-triple 10) 20) 30))
90 ((t swap12) fst_of_three) ; evaluates to 20
91 ((t swap12) snd_of_three) ; evaluates to 10
93 Write out the definition of `swap12` in Racket.
96 <LI>Define a `dup3` function that duplicates its argument to form a triple
97 whose elements are the same.
100 ((dup3 10) fst_of_three) ; evaluates to 10
101 ((dup3 10) snd_of_three) ; evaluates to 10
103 <LI>Define a `dup27` function that makes
104 twenty-seven copies of its argument (and stores them in a data structure of