[plt-scheme] HTDP: 9.5.5

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sat Sep 13 23:35:48 EDT 2008

You're definitely right that looking carefully at examples and
figuring out what particular pieces of the template work out to be for
those examples, and then working from those pieces to the whole is an
important skill to learn (and part of what Matthias meant when he said
that examples are critical).


On Sat, Sep 13, 2008 at 10:06 PM, Grant Rettke <grettke at acm.org> wrote:
>> 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:
> [else
>  ... (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
> condition?
> 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
> email.
> Please point me in the right direction to get back on track with what
> I missed from the recipe.
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.