marick / fp-oo

Code samples and exercise solutions for /Functional Programming for the Object-Oriented Programmer/
143 stars 49 forks source link

Subtrees are added to the recursion (p 171 of ecstatic earthworm) #12

Closed unclebob closed 12 years ago

unclebob commented 12 years ago

The text says you want to replace (*) expressions with a more complex expression, but the code replaces (-) expressions. The part that is underlined with ^^^^^ just seems entirely incorrect. e.g. Where did those 55555s come from?

marick commented 12 years ago

Urk. That's out-of-date code (and text saying what would be replaced with what). The correct code is:

(cond ...
      (and (zip/branch? zipper)
           (= (-> zipper zip/down zip/node) '*))
      (-> zipper
          (zip/replace '(/ 1 (+ 3 (- 0 9999))))
          zip/next
          helper)

Since the code is complicated, I also added a step-by-step explanation of how the substitution produced the final result.