[plt-scheme] HTDP 12.4.2

From: wooks wooks (wookiz at hotmail.com)
Date: Fri Jun 23 08:08:50 EDT 2006

I guess I could be persuaded that (interperse 'd empty) should give 'd. I'll 
have to think about how that helps.


----Original Message Follows----
From: Matthias Felleisen <matthias at ccs.neu.edu>
To: "wooks wooks" <wookiz at hotmail.com>
CC: dyoo at hkn.eecs.berkeley.edu, plt-scheme at list.cs.brown.edu
Subject: Re: [plt-scheme] HTDP 12.4.2
Date: Fri, 23 Jun 2006 07:21:03 -0400

Yes now you're on a roll and 90% there except that one example is wrong.

On Jun 23, 2006, at 12:45 AM, wooks wooks wrote:

>
>
>I should have said  (????? sym (first alow)) where ????? is a function that 
>inserts sym into every position in a word and heretofore i will name 
>interperse  (instead of infiltrate - more appropriate).
>
>
>The full definition is
>
>(define (insertEverywhere sym alow)
>  (cond
>    [(empty? alow) empty]
>    [else (append (interperse sym (first alow))
>                  (insertEverywhere sym (rest alow)))]
>    )
>  )
>
>Now I can't see a way to write interperse with the design recipe used so 
>far.
>
>;CONTRACT
>;interperse : symbol word - list-of-words
>; produces a list of words by interpersing symbol into each position in 
>word (including before and after)
>;
>;EXAMPLES
>;(interperse 'd (list 'e 'r)  gives
>;(list (list 'd 'e 'r)
>;       (list 'e 'd 'r)
>;       (list 'e 'r 'd))
>
>;(interperse d empty) gives empty
>;(intereperse d 'x) gives (list (list 'd 'x)
>;                               (list 'x 'd))
>;
>;TEMPLATE
>;(define (interperse sym word)
>;   (cond
>;      [(empty? word) ....]
>;      [else ....sym ... (first word)
>;                        (interperse sym (rest word))]
>;    )
>;  )
>
>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.
>
>
>
>
>----Original Message Follows----
>From: Danny Yoo <dyoo at hkn.eecs.berkeley.edu>
>To: wooks wooks <wookiz at hotmail.com>
>CC: plt-scheme at list.cs.brown.edu
>Subject: Re: [plt-scheme] HTDP 12.4.2
>Date: Thu, 22 Jun 2006 20:47:44 -0700 (PDT)
>
>
>
>On Thu, 22 Jun 2006, wooks wooks wrote:
>
>>
>>So, if we are holding onto:
>>
>>   (list (list 'd 'r 'e)
>>         (list 'r 'd 'e)
>>         (list 'r 'e 'd))
>>
>>and we want to mess with it enough so we get:
>>
>>    (list (list 'd 'e 'r)
>>          (list 'e 'd 'r)
>>          (list 'e 'r 'd)
>>          (list 'd 'r 'e)
>>          (list 'r 'd 'e)
>>          (list 'r 'e 'd))
>>
>>do you see what the difference between what we're holding onto and what we 
>>want is?  Can you give a concept or name to it?
>>
>>
>>The difference is (first alow) - Right.
>
>
>Hi Wooks Wooks,
>
>I'm not quite sure if we've done that mind meld thing yet, where we both 
>are sharing the same thoughts.  *grin* Can you be more specific?
>
>
>How can (first alow), which is going to be the list
>
>          (list 'e 'r)
>
>then account for the difference between:
>
>    (list (list 'd 'r 'e)
>          (list 'r 'd 'e)
>          (list 'r 'e 'd))
>
>
>
>which is what we have on hand, and the result that we really want to get 
>back:
>
>    (list (list 'd 'e 'r)
>          (list 'e 'd 'r)
>          (list 'e 'r 'd)
>          (list 'd 'r 'e)
>          (list 'r 'd 'e)
>          (list 'r 'e 'd))
>
>I'm not saying that it isn't, but that if we're going to say that it is, we 
>have to fill in a few more ...'s till we can tell the non-thinking computer 
>how to do what we think we mean.
>
>
>
>That is, recalling that portion of the template we were looking at earlier,
>
>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>     [else ... sym ... (first alow) ...
>           ... (insertEverywhere sym (rest alow)) ...]
>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>and knowing what the expected return value is now, can you think of how to 
>complete the definition now?
>
>
>
>If not, one way to make things easier is to fill the template will concrete 
>values, based on the test case you worked out, and see if that will help:
>
>     (... sym ... (first alow) ...
>          ... (insertEverywhere sym (rest alow)) ...)
>
>==>
>
>     (... 'd  ... (list 'e 'r) ...
>          ...  (list (list 'd 'r 'e)
>                     (list 'r 'd 'e)
>                     (list 'r 'e 'd)) ...)
>
>Does this help?
>
>
>Note that the steps we've done haven't been particularly brilliant.  One 
>could rephrase the steps we're doing here as:
>
>     1.  Shaping the general program pattern.
>     2.  Cooking up simple test cases.
>     3.  Mixing in those test case situations into the pattern.
>
>We aren't aren't doing anything that couldn't be really codified in some 
>strategy, some... well, let's call this thing a "design recipe" for lack of 
>a better term.  *wink*
>
>
>_________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme




Posted on the users mailing list.