[plt-scheme] HtDP 12.4.2 Design Recipe Blues

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Sun Mar 2 21:36:39 EST 2008

Also, your definition of:

(define(insert-everywhere/in
>
> -one-word s word)
>        (cond
>                [(empty? word)(cons(cons s empty)empty)]
>                [else(cons(cons s word)
>                        (insert-middle-end/in-one-word (cons (first word)
> empty) s (rest
> word)))]))


along with its auxiliary function looks overly complicated to me, even if it
is a working solution.

In the else clause, with the design recipe, before creating auxiliary
functions, you should ask yourself if there's some way to assemble the
correct answer using the various pieces of the inputs and the recursive call
to the function itself.  So, for example, you have the pieces:
s
(first word)
(rest word)
(insert-everywhere/in-one-word s (rest word))

Can you combine these elements to solve the answer for the else clause?
That last piece, namely (insert-everywhere/in-one-word s (rest word)), is an
important one, and if you can figure out how to use it, your auxiliary
function should be simpler and more efficient.

--Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080302/1303e36e/attachment.html>

Posted on the users mailing list.