[racket] Style mistakes (was: static variables question)

From: Stephen Bloch (bloch at adelphi.edu)
Date: Tue Feb 21 08:41:09 EST 2012

On Feb 21, 2012, at 7:18 AM, Rodolfo Carvalho wrote:

> BTW I just found the nested-cond pattern appearing on HtDP, throughout section 9:
> http://htdp.org/2003-09-26/Book/curriculum-Z-H-13.html

That happens when you follow the HtDP design recipe directly and there are conditionals for two unrelated reasons, e.g. 

(cond [(empty? L) ...]
           [(cons? L)
                (cond [(snark? (first L)) ...]
                           [(boojum? (first L)) ...]
                           [(beeblebrox? (first L)) ...]

Yes, this COULD be collapsed into
(cond [(empty? L) ...]
           [(snark? (first L)) ...]
           [(boojum? (first L)) ...]
           [(beeblebrox? (first L)) ...]
but that doesn't match the data structure as transparently.

Incidentally, if you want to bulletproof the above code against non-lists, the first version is easy: just add
            [else (error ...)]
as a new third branch of the outer "cond".  The second version doesn't bulletproof as neatly: you can either add 
            [(not (cons? L)) (error ...)]
as a new second branch of the "cond", or you can revert to the nested-cond structure.

It's a judgment call, which can go different ways in different circumstances.

Stephen Bloch
sbloch at adelphi.edu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120221/33e8bd93/attachment-0001.html>

Posted on the users mailing list.