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

 From: Eli Barzilay (eli at barzilay.org) Date: Sun Feb 19 21:10:57 EST 2012 Previous message: [racket] static variables question Next message: [racket] Style mistakes (was: static variables question) Messages sorted by: [date] [thread] [subject] [author]

```20 minutes ago, Rodolfo Carvalho wrote:
> It is possible to replace a pattern like this:
>
> (cond
>    [..a..]
>    [else (cond
>                [..b..]
>                ...)])
>
> With this simpler:
>
> (cond
>    [..a..]
>    [..b..]
>     ...)

Speaking about such transformations and about things like (if E #t #f),
I have some code which I run against student submissions to find style
problems like these, and using syntax transformations means that it's
easy to make it actually suggest the transformation.  For example,
feeding it this code:

(define (foo x y)
(cond [(< x y)
(printf "~s is smaller than ~s\n" x
y)]
[else (cond [(> x y) (printf "~s is bigger than ~s" x
y)]
[else (printf "They are ~a\n"
(if (if (eq? x y) #f #t)
"identical"
"equal"))])]))

produces this annotated printout:

(define (foo x y)
(cond [(< x y)
(printf "~s is smaller than ~s\n" x
;;>                                        A
;;> (A) this expression (and the rest) should be on a separate line (or
;;>     make the whole `printf' fit on one line)
y)]
[else (cond [(> x y) (printf "~s is bigger than ~s" x
;;>           A              B
;;> (A) flatten this into the surrounding `cond'
;;> (B) make this form fit on one line, or put it on a separate line
y)]
[else (printf "They are ~a\n"
(if (if (eq? x y) #f #t)
;;>                                   A
;;> (A) `if' not needed, just use (not (eq? x y))
"identical"
"equal"))])]))
;;>                               A