I love it!<div><br></div><div>Ron Paul Middle school, 2024, Ms. Anderson's 5th grade:</div><div><br></div><div>"But Teacher, when I ran 'StyleNazi' like you told us to, it just came back with:</div><div> 'here's a phone card, call your mother...' "</div>
<div><br></div><div>-Joe<br><br><div class="gmail_quote">On Sun, Feb 19, 2012 at 6:10 PM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
20 minutes ago, Rodolfo Carvalho wrote:<br>
> It is possible to replace a pattern like this:<br>
><br>
> (cond<br>
> [..a..]<br>
> [else (cond<br>
> [..b..]<br>
> ...)])<br>
><br>
> With this simpler:<br>
><br>
> (cond<br>
> [..a..]<br>
> [..b..]<br>
> ...)<br>
<br>
Speaking about such transformations and about things like (if E #t #f),<br>
I have some code which I run against student submissions to find style<br>
problems like these, and using syntax transformations means that it's<br>
easy to make it actually suggest the transformation. For example,<br>
feeding it this code:<br>
<br>
(define (foo x y)<br>
(cond [(< x y)<br>
(printf "~s is smaller than ~s\n" x<br>
y)]<br>
[else (cond [(> x y) (printf "~s is bigger than ~s" x<br>
y)]<br>
[else (printf "They are ~a\n"<br>
(if (if (eq? x y) #f #t)<br>
"identical"<br>
"equal"))])]))<br>
<br>
produces this annotated printout:<br>
<br>
(define (foo x y)<br>
(cond [(< x y)<br>
(printf "~s is smaller than ~s\n" x<br>
;;> A<br>
;;> (A) this expression (and the rest) should be on a separate line (or<br>
;;> make the whole `printf' fit on one line)<br>
y)]<br>
[else (cond [(> x y) (printf "~s is bigger than ~s" x<br>
;;> A B<br>
;;> (A) flatten this into the surrounding `cond'<br>
;;> (B) make this form fit on one line, or put it on a separate line<br>
y)]<br>
[else (printf "They are ~a\n"<br>
(if (if (eq? x y) #f #t)<br>
;;> A<br>
;;> (A) `if' not needed, just use (not (eq? x y))<br>
"identical"<br>
"equal"))])]))<br>
;;> A<br>
;;> (A) misleading "flat" indentation<br>
<br>
Actually, there's a few more things it prints -- it's not intended to<br>
be used without a human going over its output. In case someone is<br>
interested in such a project I can send out the code. It could even<br>
make a cute drracket tool that criticizes your code...<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br>
<a href="http://barzilay.org/" target="_blank">http://barzilay.org/</a> Maze is Life!<br>
<br>
____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</font></span></blockquote></div><br></div>