[plt-scheme] HTDP: 9.5.5

From: Grant Rettke (grettke at acm.org)
Date: Sat Sep 13 23:06:16 EDT 2008

> Now discover Jens's hint by following the design recipe.

Where did I go wrong? (Here is not where I expect you to be psychic,
so let me elaborate)

I followed the recipe by defining the recursive data (I re-used list
of numbers), created a bunch of tests, walked through the
implementation of the body (cond clauses, selector expressions,
natural recursion), implemented the answer for the base case (zero),
and then was left with:

 ... (first a-list-of-numbers) ...
 ... (convert (rest a-list-of-numbers) ...)]

I think I was too preoccupied with shoe-horning in my approach than
looking at the data. What I *didn't* do was to take something one more
complex than the base case, like this, which is a test I had written
before I implemented the function:

(check-expect (convert (cons 1 empty)) 1)

That at least would have gotten me to the first part of the equation
in the else clause, 1 plus ...

Then I would have looked at:

(check-expect (convert (cons 0 (cons 1 empty))) 10)

and maybe though zero plus something times the 2nd part, and finally plus zero.

Is that the thought process, step by step satisfy the test by revising
the calculation? You start with the simplest thing from the base

My approach thus far has been to write *all* of the tests up front, I
was staring at this while I tried to implement the body:

(check-expect (convert empty) 0)
(check-expect (convert (cons 1 empty)) 1)
(check-expect (convert (cons 0 (cons 1 empty))) 10)
(check-expect (convert (cons 1 (cons 1 empty))) 11)
(check-expect (convert (cons 0 (cons 0 (cons 1 empty)))) 100)
(check-expect (convert (cons 1 (cons 1 (cons 1 empty)))) 111)

This was a point where I totally didn't understand it and I felt like
the recipe wasn't taking me there, which I was I posted a long-ish

Please point me in the right direction to get back on track with what
I missed from the recipe.

Posted on the users mailing list.