[plt-scheme] HTDP 12.4.2

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Fri Jun 23 09:58:16 EDT 2006

> Now I can't see a way to write interperse with the design recipe used so 
> far.

Hi Wooks Wooks,

Let's look at some of the test cases you have so far.

> ;(interperse d empty) gives empty
> ;(intereperse d 'x) gives (list (list 'd 'x)
> ;                               (list 'x 'd))

Almost.  The second test example you've written can't work.  Do you know 
why?  Take a look again at the contract:

;interperse : symbol word - list-of-words

> ;(define (interperse sym word)
> ;   (cond
> ;      [(empty? word) ....]
> ;      [else ....sym ... (first word)
> ;                        (interperse sym (rest word))]
> ;    )
> ;  )

Yup, the template here seems ok now.

I'd recommend adding another test case or two to handle slightly larger 
lists, maybe lists of two and three elements just to make things managable 
but interesting.

Once your test cases are clean, can you try doing the 
'template-value-insertion' thing we tried from insertEverywhere with a 
list of three elements?  See how far you can get from there, and we can 
continue if you get stuck.

> It still looks to me that I will need some auxiliary function similar to 
> what I did with the original infiltrate though (split the word into 2 
> parts and generate words by inserting symbol between each respective 
> split combination.

In this particular example, it's actually possible to do without the 
additional auxiliary.  Play it through --- I think you'll be surprised by 
the definition once you get it it, because it isn't obvious, but it's very 

Good luck!

Posted on the users mailing list.