changes
[lambda.git] / assignment10.mdwn
index 087b66a..ba4df37 100644 (file)
@@ -39,15 +39,16 @@ Of course, if you need help or want us to review your efforts, we'll be glad to
        solution that traverses the tree exactly once, replacing each
        leaf as soon as you see it?
 
-       Consider a variation in which you must replace each leaf with
-       its number of occurrences in the tree.  Is there any way to do
-       that with a single traversal?
-
        You can assume that the tree is binary, leaf-labeled (no
        labels on the internal nodes), and that the leafs are, say,
        chars.
 
-       Here is [a hint](/hints/assignment_10_hint).
+       Here is [a hint](/hints/assignment_10_hint_1).
+
+       Consider a variation in which you must replace each leaf with
+       its number of occurrences in the tree.  Is there any way to do
+       that with a single traversal? (Here is [a hint](/hints/assignment_10_hint_2).)
+
 
 
 2.     Armed with your solution to problem 1, try this: you have as input a leaf-labeled, binary tree whose labels are strings. You also have as input an interpretation function from strings to meanings. Let the meanings of your strings be primitive elements, for instance:
@@ -114,7 +115,7 @@ Of course, if you need help or want us to review your efforts, we'll be glad to
 
        What would be a helper function you could supply as a `k` that would report `#t` iff the original `lst` contained more instances of some symbol than non-instances?
 
-<!--
+       <!--
                (define remove-co
                  (lambda (a lst k)
                    (cond
@@ -124,7 +125,7 @@ Of course, if you need help or want us to review your efforts, we'll be glad to
                       (remove-co a (cdr lst) (lambda (left right) (k left (cons (car lst) right)))))
                      (else
                       (remove-co a (cdr lst) (lambda (left right) (k (cons (car lst) left) right)))))))
--->
+       -->
 
 5.     Now we define a function `insert-co` which has the following behavior. It accepts as arguments three symbols, a list, and a handler. The first symbol is inserted before (to the left of) any occurrences in the list of the second symbol, and after (to the right of) any occurrences of the third symbol. The handler is then called with three arguments: the new list (with the insertions made), the number of "to-the-left" insertions that were made, and the number of "to-the-right" insertions that were made.
 
@@ -142,7 +143,7 @@ Of course, if you need help or want us to review your efforts, we'll be glad to
                      (else
                       (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) ________))))))
 
-<!--
+       <!--
                (define insert-co
                  (lambda (new before after lst k)
                    (cond
@@ -151,10 +152,10 @@ Of course, if you need help or want us to review your efforts, we'll be glad to
                      ((eq? (car lst) before)
                       (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) (k (cons new (cons before new-lst)) (succ lefts) rights))))
                      ((eq? (car lst) after)
-                      (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) (k (cons (after (cons new new-lst))) lefts (succ rights)))))
+                      (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) (k (cons after (cons new new-lst)) lefts (succ rights)))))
                      (else
                       (insert-co new before after (cdr lst) (lambda (new-lst lefts rights) (k (cons (car lst) new-lst) lefts rights)))))))
--->
+       -->
 
 
 6.     Go back to the "abSd" problem we presented in [[From List Zippers to Continuations]]. Consider the "tc" solution which uses