one more exercise
[lambda.git] / exercises / assignment2_answers.mdwn
index 177aa2d..04c103c 100644 (file)
@@ -199,6 +199,7 @@ Folds and Lists
           reverse xs = fold_right (f, []) xs
         in reverse
 
           reverse xs = fold_right (f, []) xs
         in reverse
 
+    <a id=cps-reverse></a>
     *Here is an elegant, efficient answer following the [[hint|assignment2 hint]]*
 
     Suppose the list we want to reverse is `[10, 20, 30]`. Applying `fold_right` to this will begin by computing `f (30, z)` for some `f` and `z` that we specify. If we made the result of that be something like `30 & blah`, or any larger structure that contained something of that form, it's not clear how we could, using just the resources of `fold_right`, reach down into that structure and replace the `blah` with some other element, as we'd evidently need to, since after the next step we should get `30 & (20 & blah)`. What we'd like instead is something like this:
     *Here is an elegant, efficient answer following the [[hint|assignment2 hint]]*
 
     Suppose the list we want to reverse is `[10, 20, 30]`. Applying `fold_right` to this will begin by computing `f (30, z)` for some `f` and `z` that we specify. If we made the result of that be something like `30 & blah`, or any larger structure that contained something of that form, it's not clear how we could, using just the resources of `fold_right`, reach down into that structure and replace the `blah` with some other element, as we'd evidently need to, since after the next step we should get `30 & (20 & blah)`. What we'd like instead is something like this:
@@ -237,7 +238,7 @@ Folds and Lists
               reverse xs = (fold_right (f, id) xs) []
             in reverse
 
               reverse xs = (fold_right (f, id) xs) []
             in reverse
 
-    The ideas here are explored further in Chapter 8 of *The Little Schemer*. There they first introduce the idea of passing function as arguments to other functions, and having functions be the return values from functions. The `multirember&co` function discussed on pp. 137--140 (and the other `...&co` functions discussed in that chapter) are more complex examples of the kind of strategy used here to define `reverse`. We will be returning to these ideas and considering them more carefully later in the term.
+    The ideas here are explored further in Chapter 8 of *The Little Schemer*. There they first introduce the idea of passing function as arguments to other functions, and having functions be the return values from functions. Then the `multirember&co` function discussed on pp. 137--140 (and the other `...&co` functions discussed in that chapter) are more complex examples of the kind of strategy used here to define `reverse`. We will be returning to these ideas and considering them more carefully later in the term.
 
 
 Numbers
 
 
 Numbers