[plt-scheme] Re: HtDP 26.1.2

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Sat Mar 21 18:53:05 EDT 2009

Dave wrote:
> Additional question --
>
> Is this how merge-neighbors supposed to process asymmetrical lists?
>
> (check-expect (merge-neighbors (list (list 3 7) (list 5))) (list 3 5
> 7))
>
>   

Yes.

Chongkai

> Thanks,
>
> Dave
>
> On Mar 21, 3:26 pm, dave yrueta <dyru... at gmail.com> wrote:
>   
>> Hi all --
>>
>> Question about HtDP function "merge-neighbors:"
>>
>> Link to exercise:  http://www.htdp.org/2003-09-26/Book/curriculum-Z-H-33.html#node_sec_26.1
>>
>> The text describes the contract for "merge-neighbors" as a function
>> which "merges pairs of neighboring lists. More specifically, it
>> consumes a list of lists (of numbers) and merges neighbors. For
>> example,
>>
>> (equal? (merge-all-neighbors (list (list 2) (list 5) (list 9) (list
>> 3)))
>>         (list (list 2 5) (list 3 9))) "
>>
>> In the example, however, it seems that in addition to merging pairs of
>> neighboring lists, "merge-neighbors" also sorts each pair of lists in
>> ascending order before combining them.  In other words --
>>
>> (check-expect (merge-all-neighbors (list (list 9) (list 1)) (list
>> (list 1 9))?
>>
>>     

Yes, merge-all-neighbors also sorts each pair of lists.

>> Further, suppose the function input is a list of list-of-numbers in
>> descending order --
>>
>> (define list1 (list (list 9) (list 7) (list 5) (list 3))).
>>
>> In this case, does "merge-all-neighbors" evaluate list1 to (list (list
>> 7 9) (list 3 5)) --
>>
>> -- or to (list (list 3 5) (list 7 9)).
>>
>>     

The former, (list (list 7 9) (list 3 5)).

>> Thanks!
>>
>> Dave Yrueta
>>
>> _________________________________________________
>>   For list-related administrative tasks:
>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>     
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>   



Posted on the users mailing list.