<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div><br></div><div>* What does it mean to merge two neighbors: </div><div><br></div><div> (merge (list 1 3 9) (list 0 4 8)) </div><div> --> </div><div>(list (list 0 1 3 4 8 9))</div><div><br></div><div>* Which design recipe applies? </div><div><br></div><div>* Work systematically and it all falls out. </div><div><br></div><br><div><div>On Mar 21, 2009, at 7:50 PM, David Yrueta wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Matthias --<div><br></div><div>Thank you for your response.</div><div><br></div><div>I'm still a bit confused. </div><div><br></div><div>How can this accomplished --</div><div><br></div><div>(check-expect (merge-all-neighbors (list (list 9) (list 1))) (list (list 1 9)))?<br> </div><div><br></div><div>-- without some sorting going on within "merge-all-neighbors"?</div><div><br></div><div>I would expect a function which only appended contiguous lists would evaluate like this --</div><div> <br></div><div>(check-expect (merge-all-neighbors (list (list 1) (list 9))) (list (list 1 9)))</div><div>(check-expect (merge-all-neighbors (list (list 9) (list 1))) (list (list 9 1)))<br></div><div><br></div><div>But instead, in both cases above, "merge-all-neighbors" returns (list (list 1 9)), yes?</div> <div><br></div><div>Where am I going wrong?</div><div><br></div><div>Thanks!</div><div>Dave</div><div><br></div><div><br><br><div class="gmail_quote">On Sat, Mar 21, 2009 at 4:29 PM, Matthias Felleisen <span dir="ltr"><<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im"><br> On Mar 21, 2009, at 6:26 PM, dave yrueta wrote:<br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi all --<br> <br> Question about HtDP function "merge-neighbors:"<br> <br> Link to exercise: <a href="http://www.htdp.org/2003-09-26/Book/curriculum-Z-" target="_blank">http://www.htdp.org/2003-09-26/Book/curriculum-Z-</a>H-33.html#node_sec_26.1<br> <br> The text describes the contract for "merge-neighbors" as a function<br> which "merges pairs of neighboring lists. More specifically, it<br> consumes a list of lists (of numbers) and merges neighbors. For<br> example,<br> <br> (equal? (merge-all-neighbors (list (list 2) (list 5) (list 9) (list<br> 3)))<br> (list (list 2 5) (list 3 9))) "<br> <br> In the example, however, it seems that in addition to merging pairs of<br> neighboring lists, "merge-neighbors" also sorts each pair of lists in<br> ascending order before combining them.<br> </blockquote> <br></div> No!<div class="im"><br> <br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> In other words --<br> <br> (check-expect (merge-all-neighbors (list (list 9) (list 1)) (list (list 1 9))?<br> </blockquote> <br></div> This example wouldn't contradict the exercise. Indeed, it jives just fine.<div class="im"><br> <br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Further, suppose the function input is a list of list-of-numbers in<br> descending order --<br> <br> (define list1 (list (list 9) (list 7) (list 5) (list 3))).<br> <br> In this case, does "merge-all-neighbors" evaluate list1 to (list (list<br> 7 9) (list 3 5)) --<br> </blockquote> <br></div> This one obviously. But now run merge-all-neighbors on the result and see what you get.<br> <br> -- Matthias<div class="im"><br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> -- or to (list (list 3 5) (list 7 9)).<br> </blockquote> <br></div> That would be a function that merges neighbors and re-arranges things in addition.<div><div></div><div class="h5"><br> <br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <br> Thanks!<br> <br> Dave Yrueta<br> <br> <br> <br> <br> <br> _________________________________________________<br> For list-related administrative tasks:<br> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br> </blockquote> <br> </div></div></blockquote></div><br></div></blockquote></div><br></body></html>