[plt-scheme] Loosing sleep over htdp exercise 12.4.2
On Mar 6, 2010, at 3:01 PM, Horace Dynamite wrote:
> ; EXAMPLES FOR DATA
> ; words;
> ; empty,
> ; 1-letter word: (cons 'a empty)
> ; 3-letter word: (cons 'a (cons 'p (cons 'e empty)))
> ; n-letter word: (cons x1 (cons x2 ( ... (cons xn-1 (cons xn
> empty)))
> ; low;
> ; 0 words: empty
> ; 1-word: (cons (cons 'a empty) empty)
> ; 3-words: (cons (cons (cons 'a empty)
> ; (cons (cons 'b empty)
> ; (cons (cons 'c empty)
> ; empty)))
> ; empty)
Sounds good so far. Now are you actually going to USE these examples
for your functions?
You give no examples for arrangements (although as you point out, the
book provides two examples).
You give only one example for insert-everywhere/in-all-words; you
don't test the function on an empty list of words, nor on a list
containing an empty word. In my class, you would lose points for
"choice of test cases".
You give only one example for insert-everywhere/in-one-word; you
don't test the function on an empty word. Ditto.
You give only one example for insert-around-word; you don't test the
function on an empty word. Ditto.
You give two examples for insert-between-word; neither of them is
empty, or even just a single letter. Ditto.
insert-everywhere/in-one-word starts out following the usual template
for functions on lists, but then chickens out and doesn't call itself
recursively on the rest of the list; instead, it calls insert-around-
word and insert-between-word, which strike me as an odd, artificial
way to subdivide the work.
Your contract for insert-between-word says it takes in a word, but in
fact it seems to assume that the word is non-empty (it calls "rest"
before checking whether there IS a "rest").
Hope that helps.
Stephen Bloch
sbloch at adelphi.edu