[plt-scheme] HTDP 12.4.2

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Fri Jun 23 09:18:19 EDT 2006

>At 4:43 AM +0100 6/22/06, wooks wooks wrote:
>;CONTRACT
>;insertEverywhere : symbol ('a - 'z) list-of-words - list of words
>;returns a list of words constructed by interpersing symbol before, 
>after and between each letter, of
>;each word in the list-of-words

Much better.

>;EXAMPLES
>;(insertEverywhere 'd
>;  (cons (cons 'e (cons 'r empty))
>;    (cons (cons 'r (cons 'e empty))
>;      empty))) gives
>; (list (list 'd 'e 'r)
>;       (list 'e 'd 'r)
>;       (list 'e 'r 'd)
>;       (list 'd 'r 'e)
>;       (list 'r 'd 'e)
>;       (list 'r 'e 'd))

OK, that's one good example.  You'd still lose a point in my class 
for insufficient examples: add an empty example, and (ideally) an 
example in which one of the WORDS in the list is empty.  In most 
cases, the empty example is really easy.  In this case, it's not 
immediately obvious what the right answer should be for the empty 
list (there are two plausible "right answers"), which indicates that 
you need to think about this before going any farther on writing the 
code.  (Hint: think about the NUMBER of words that should be in the 
result, as a function of the number and length of words in the input.)


I would also recommend writing the example in such a way that it's 
easy to test, e.g.
(insertEverywhere 'd
   (list (list 'e 'r) (list 'r 'e))
"should be"
(list (list 'd 'e 'r)
        (list 'e 'd 'r)
        (list 'e 'r 'd)
        (list 'd 'r 'e)
        (list 'r 'd 'e)
        (list 'r 'e 'd))
Note that this is NOT commented out.  When you write the actual 
function definition, put it AHEAD of this in the definitions window, 
and you can test your code by simply hitting the "Run" button and 
comparing the actual output with what it "should be".

Or, instead of all this, you can use DrScheme's "test case" feature.


Another suggestion: try an example in which the input isn't such a 
"special case", e.g.
(insertEverywhere 'd (list (list 'x) (list) (list 'r 'e)))
I know, that kind of input will never be given to the function when 
it's used in the context of the arrangements function, but it'll 
actually be less confusing and more helpful to you than a "special" 
input like the one you selected.

-- 
					Stephen Bloch
					sbloch at adelphi.edu


Posted on the users mailing list.