[plt-scheme] HtDP newbie question, 12.4.2
Hi all,
I am trying to learn HtDP by myself, and like Dave Yrueta I am stumped by 12.4.2. It seems like such a simple problem---insert a letter x into a list of words---but it's really a killer. I'd be very grateful for any suggestions.
;FUNCTION: "insert-everywhere/in-all-words"
;Data Definition:
; a WORD is either (1) empty, or (2) (cons s w) where s is a symbol and w is a word
;Contract:
;insert-everywhere/in-all-words : symbol list-of-words --> list-of-words
; Purpose: to insert a symbol between every letter of every word, e.g. X, AT-->XAT, AXT, ATX.
;Function Template:
(define (insert-everywhere/in-all-words s low)
(cond
[(empty? (rest low))...]
[else ...(first low)...insert-everywhere/in-all-words s (rest low)]))
Note:
It is suggested to use "append", which is easy one or two times---(append x word) or (append (append (first word) x) (rest word))----but I can't see how to use this recursively for an arbitrary number of letters and words.
The fact that the "hint" refers to the keyword list, which the book hasn't covered yet, makes me wonder if it's even possible to answer this problem, given what we know so far...
Thanks very much,
Cooke
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080325/209b8127/attachment.html>