refine hidden assignment2
[lambda.git] / topics / _assignment2.mdwn
index 2ca8ede..7a9ea03 100644 (file)
@@ -22,34 +22,33 @@ Recall our definitions of true and false.
 
 In Racket, these functions can be defined like this:
 
-       (define true (lambda (t) (lambda (f) t)))
-       (define false (lambda (t) (lambda (f) f)))
+    (define true (lambda (t) (lambda (f) t)))
+    (define false (lambda (t) (lambda (f) f)))
 
 (Note that they are different from Racket's *primitive* boolean values `#t` and `#f`.)
 
-<OL start=8>
-<LI>Define a `neg` operator that negates `true` and `false`.
+<small>(I know the numbering of the homework problems will restart instead of continuing as before. It's too much of a pain to fix it right now. We'll put in a better rendering engine later that will make this work right without laborious work-arounds on our part.)</small>
 
-Expected behavior: 
+8.  Define a `neg` operator that negates `true` and `false`.
 
-    (((neg true) 10) 20)
+    Expected behavior: 
 
-evaluates to 20, and 
+        (((neg true) 10) 20)
 
-    (((neg false) 10) 20)
+    evaluates to 20, and 
 
-evaluates to 10.
+        (((neg false) 10) 20)
 
-<LI>Define an `or` operator.
+    evaluates to 10.
 
-<LI>Define an `xor` operator. If you haven't seen this term before, here's a truth table:
+9.  Define an `or` operator.
 
-    true xor true == false
-    true xor false == true
-    false xor true == true
-    false xor false == false
+10. Define an `xor` operator. If you haven't seen this term before, here's a truth table:
 
-</OL>
+        true xor true == false
+        true xor false == true
+        false xor true == true
+        false xor false == false
 
 
 
@@ -62,19 +61,19 @@ Recall our definitions of ordered triples.
 
 To extract the first element of a triple t, you write:
 
-       t (\fst snd trd. fst)
+    t (\fst snd trd. fst)
 
 Here are some definitions in Racket:
 
-       (define make-triple (lambda (fst) (lambda (snd) (lambda (trd) (lambda (f) (((f fst) snd) trd))))))
-       (define fst_of_three (lambda (fst) (lambda (snd) (lambda (trd) fst))))
-       (define snd_of_three (lambda (fst) (lambda (snd) (lambda (trd) snd))))
+    (define make-triple (lambda (fst) (lambda (snd) (lambda (trd) (lambda (f) (((f fst) snd) trd))))))
+    (define fst_of_three (lambda (fst) (lambda (snd) (lambda (trd) fst))))
+    (define snd_of_three (lambda (fst) (lambda (snd) (lambda (trd) snd))))
 
 Now we can write:
 
-       (define t (((make-triple 10) 20) 30))
-       (t fst_of_three)  ; will evaluate to 10
-       (t snd_of_three)  ; will evaluate to 20
+    (define t (((make-triple 10) 20) 30))
+    (t fst_of_three)  ; will evaluate to 10
+    (t snd_of_three)  ; will evaluate to 20
 
 If you're puzzled by having the triple to the left and the function that
 operates on it come second, think about why it's being done this way: the pair
@@ -83,27 +82,23 @@ argument*, and returns *the result of* operating on its elements with that
 function. In other words, the triple is a higher-order function.
 
 
-<OL start=13>
-<LI>Define the `swap12` function that permutes the elements of a triple. Expected behavior:
+11. Define the `swap12` function that permutes the elements of a triple. Expected behavior:
 
-       (define t (((make-triple 10) 20) 30))
-       ((t swap12) fst_of_three) ; evaluates to 20
-       ((t swap12) snd_of_three) ; evaluates to 10
+        (define t (((make-triple 10) 20) 30))
+        ((t swap12) fst_of_three) ; evaluates to 20
+        ((t swap12) snd_of_three) ; evaluates to 10
 
-Write out the definition of `swap12` in Racket.
+    Write out the definition of `swap12` in Racket.
 
 
-<LI>Define a `dup3` function that duplicates its argument to form a triple
-whose elements are the same.
-Expected behavior:
+12. Define a `dup3` function that duplicates its argument to form a triple
+whose elements are the same.  Expected behavior:
 
-       ((dup3 10) fst_of_three) ; evaluates to 10
-       ((dup3 10) snd_of_three) ; evaluates to 10
+        ((dup3 10) fst_of_three) ; evaluates to 10
+        ((dup3 10) snd_of_three) ; evaluates to 10
 
-<LI>Define a `dup27` function that makes
+13. Define a `dup27` function that makes
 twenty-seven copies of its argument (and stores them in a data structure of
 your choice).
 
-</OL>
-