[plt-scheme] HTDP 12.4.2
On Jun 23, 2006, at 3:05 PM, wooks wooks wrote:
> (interperse 'f (list 'd 'a 'r 'k))
>
> gives
>
> (list (list 'f 'd 'a 'r 'k) (list 'f 'a 'r 'k) (list 'f 'r 'k) (list
> 'f 'k) 'f)
>
> and I want
>
> (list (list 'f 'd 'a 'r 'k) (list 'd 'f 'a 'r 'k) (list 'd 'a 'f 'r
> 'k) (list 'd 'a 'r 'f 'k) (list 'd 'a 'r 'k 'f))
Change the formating of the two things and take a close look:
(list (list 'f 'd 'a 'r 'k) (list 'f 'a 'r 'k) (list 'f 'r 'k)
(list 'f 'k) 'f)
(list (list 'f 'd 'a 'r 'k) (list 'd 'f 'a 'r 'k) (list 'd 'a 'f 'r 'k)
(list 'd 'a 'r 'f 'k) (list 'd 'a 'r 'k 'f))
When you recur with (rest word) you are dropping the first letter, at
each stage. So not surprisingly, the prefix is lost.
Try with an example of length two and see whether you can come up with
a better idea.