[racket-dev] Simple loop checking in beginner?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Wed Nov 10 12:22:44 EST 2010

The value in the large comes when the data structures are more complex
(in the function below you'd use a loop or filter, of course). When
they are larger, you can pinpoint where to change your function based
on a change to your data definition.

For example, consider writing an interpreter. Now imagine the language
changes in some way -- you can read off where exactly to change the
interpreter.

Robby

On Wed, Nov 10, 2010 at 10:02 AM, namekuseijin <namekuseijin at gmail.com> wrote:
> I see the reasoning now, I apologize.  It's a good choice for
> students, not so sure about ye old daily buggy sofware maintenance.
>
> OTOH, perhaps if this practice was widespread it would lead to less
> bugs or at least more maintenable software.  At least for those aware
> of this "idiom".
>
> On Wed, Nov 10, 2010 at 1:44 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> On Nov 10, 2010, at 10:40 AM, namekuseijin wrote:
>>
>>> On Wed, Nov 10, 2010 at 12:13 AM, John Clements
>>> <clements at brinckerhoff.org> wrote:
>>>> ;; NOW I'M A STUDENT:
>>>>
>>>> ;; 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
>>>
>>> then again, may be someone who had previous exposure to lesser languages...
>>
>>
>> Perhaps you should ask before you critique.
>> We insist on this style:
>>
>>  -- the outer cond corresponds to the structure of the data definition of the input
>>  -- the inner one signals decision relevant for the output
>>        (I would use an 'if' for the inner one, but over N years of programming
>>        as if a student might see my code one day, I have come to really, truly
>>        like the unconditional use of cond for the layout purpose)
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev
>


Posted on the dev mailing list.