[plt-scheme] HTDP 14.3.4 lists within lists.

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 31 10:03:01 EDT 2009

Dave, you have two distinct, slightly related concerns:

1. why do you think your function is wrong?

2. just because others have used max to define the function, you  
should not jump to any conclusions about their solution being better  
or worse than yours.

To answer question 1, you need to come up with a test case for which  
you expect one result and your function produces a different one.  
(Indeed, you should also have an argument as to why your expected  
result is the one you want.)

To answer question 2, you should study whether your solution is  
equivalent to the others in some way. Here is a start:

-- cond is an expression. 
-- You can add 1 to the result of a cond. 
-- if all branches of a cond add 1 to something, you can move this  
-- SO: your cond is equivalent to 

  (+ 1
       [(>= (depth (first wp)) (depth (rest wp))) (depth (first wp))]
       [else                                      (depth (rest wp))]))

As you can easily see now, the cond picks the larger of the values  
(depth (first wp)) and (depth (rest wp)), meaning you could write  
this also as

  (+ 1 (max (depth (first wp)) (depth (rest wp))))

Now you can compare and contrast with the other solution. -- Matthias

Posted on the users mailing list.