[racket] Style mistakes (was: static variables question)
I love it!
Ron Paul Middle school, 2024, Ms. Anderson's 5th grade:
"But Teacher, when I ran 'StyleNazi' like you told us to, it just came back
with:
'here's a phone card, call your mother...' "
-Joe
On Sun, Feb 19, 2012 at 6:10 PM, Eli Barzilay <eli at barzilay.org> wrote:
> 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
> ;;> (A) misleading "flat" indentation
>
> Actually, there's a few more things it prints -- it's not intended to
> be used without a human going over its output. In case someone is
> interested in such a project I can send out the code. It could even
> make a cute drracket tool that criticizes your code...
>
> --
> ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
> http://barzilay.org/ Maze is Life!
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120219/79d996ee/attachment.html>