# [plt-scheme] HTDP: 14.3.4 Retaining Values

 From: Matthias Felleisen (matthias at ccs.neu.edu) Date: Sat Sep 27 12:45:59 EDT 2008 Previous message: [plt-scheme] HTDP: 14.3.4 Retaining Values Next message: [plt-scheme] microphone Messages sorted by: [date] [thread] [subject] [author]

```P.S. The design that you came up with also has a name:

structural recursion with accumulator

It is neither required nor really desirable in this particular
situation.

As you move beyond Part III in HtDP (up to VI) you will encounter the
following:

structural recursion design
design by abstraction, use of abstraction (aka "loops")
generative recursion design (quick sort, merge sort vs insertion sort)
structural and generative recursive design with accumulators

On exams and homeworks, I ask my students to identify which design
strategy they chose to solve the problem to make them more
conscientious problem solvers. Not everyone who solves a problem

;; ---

Also note that HtDP (and HtDC) expose the Turing Tarpit Problem of
Homework Assignments. Most people think that after introducing
students to assignments, if, for/while, and arrays, the kids can more
or less solve any problem. In principle they are correct because the
language is equivalent to Turing machines.

In reality though, students don't know enough problem solving
strategies to crack all problems nor do they understand enough about
iterative refinement, the other theme in HtDP/C. So HtD is carefully
designed so that all problems stated in section N can be solved with
nothing but the problem solving strategies from sections 1 .. N and
usually in a direct and immediate manner. Of course, the more you get
to know problem solving strategies the less "immediate and obvious"
things become because you can challenge students with more complex
problems.

;; ---

If you also move beyond Part VI, you will get

structural/generative recursive design with state manipulation

This is difficult, and I have started pushing this part into the HtDC
part of the first year because I want more time for basic strategies
to sink in.

On Sep 27, 2008, at 12:13 PM, Geoffrey Lane wrote:

> I hope this is ok, it's my first post to the group.
>
> 14.3.4 Basically counts the max depth of nested lists (what are called
> Web Pages in the example)
> '(foo) is 0 - no nesting
> '(foo (bar)
>        (baz)
>        (quux (zorch))) is 3 for the maximum depth.
>
> It's supposed to just take the Web Page (list of lists) - but I could
> only figure it out when I passed an initial zero that I could then
> increment in the proper condition (when I'm going down a level).
> Am I missing something? The reason I ask, is there's a question in 15
> that wants to do a similar thing.
>
> Code I came up with:
>
> ;; depth: WP  ->  number
> ;; to count the depth of sub-pages that occur in a-wp
> (define (depth a-wp n)
> (count-depth a-wp 0))
>
> ;; count-depth: WP number -> number
> ;; count the depth of the sub-pages of a-wp
> (define (count-depth a-wp n)
> (cond
>   [(empty? a-wp) n]
>   [(symbol? (first a-wp)) (count-depth (rest a-wp) n)]
>   [else (max (count-depth (first a-wp) (add1 n)) (count-depth (rest a-
> wp) n))]))
>
> Thanks for the help.
>
> --
> Geoff Lane <geofflane at gmail.com>
>
>
>
> _________________________________________________