[racket-dev] Simple loop checking in beginner?

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Wed Nov 10 10:44:30 EST 2010

On Wed, Nov 10, 2010 at 10:40 AM, namekuseijin <namekuseijin at gmail.com> wrote:
> On Wed, Nov 10, 2010 at 12:13 AM, John Clements
> <clements at brinckerhoff.org> wrote:
>> ;; only-long-strings : (listof string) -> (listof string)
>> ;; return a list containing the strings longer than 2 chars
>> (define/noloop (only-long-strings l)
>>  (cond [(empty? l) empty]
>>        [else (cond [(< 2 (string-length (first l)))
>>                     (cons (first l)
>>                           (only-long-strings (rest l)))]
>>                    [else (only-long-strings l)])]))
> gosh, students do suck.  I guess you teach them to use cond because
> it's a generalized if.  But then they proceed to use it just like if:
> always two conditions per (verbose) cond! :p

I disagree - the outer `cond' has 2 clauses because it it processing a
data definition - (listof string) - which has 2 clauses.  The second
`cond' clause, which processes conses, has a conditional as well, but
there's certainly nothing wrong with having the structure of your
program match the structure of your data, especially not for HtDP
sam th
samth at ccs.neu.edu

Posted on the dev mailing list.