[plt-scheme] Re: HTDP Exercise 12.4.2 ... Help!

From: S Brown (ontheheap at gmail.com)
Date: Sun Apr 26 13:10:27 EDT 2009

On Apr 26, 9:13 am, Stephen Bloch <sbl... at adelphi.edu> wrote:

> > , so all I need to do with the s is just add it to the
> > beginning, and I can do that using append, so I know that line can
> > become (append (list s) (first a-low)).
> This part of the sentence I don't buy: this is PART of what's
> missing, but not all of what's missing.

I don't know how I didn't see this before! Instead of calling append
on (list s) (first a-low), what I need is to call append on another
function which takes as it's arguments a symbol and a single word,
which returns a list of words where the symbol has been been inserted
before and after each letter in the word. In other words, where insert-
everywhere/in-all-words is concerned with a list of words, my new
function is only concerned with a single word.

So, now it's a matter of going through the design process for my new
function, which I'm going to call insert-everywhere.

;; insert-everywhere: symbol word  ->  list-of-words
;; to create a list-of-words where symbol s is inserted before
;; and after each letter in the word w
(define (insert-everywhere s w)
      ((empty? w) ... s ...)
      (else ... s (first w) ...
            ... (insert-everywhere s (rest w)) ...)))

I think this makes sense. Now it's a matter of completing each cond
line in my new function insert-everywhere..

Posted on the users mailing list.