[racket] Looking for feedback on code style

From: Scott Hickey (jscotthickey at gmail.com)
Date: Wed Sep 8 23:35:49 EDT 2010

I was helping my son with his math homework tonight, working with
medians and wrote the following below. As I was looking at it, I was
wondering:

1) Is this an idiomatic use for let - is there too much code for
middle-position in the let?
2) Should 2 be on its own line at the end of my function really be on
the line above?
3) Is it becoming idiomatic to be using square brackets in the let?
4) Are my variable names more verbose than what you'd see in mature scheme code?
5) If this was a piece of production code, would it be ok or make an
experienced schemer cringe?

Hopefully the formatting from DrScheme was preserved in this post:

(define (median alist)
 (let ((sorted-list (sort alist <))
       (middle-position (- (quotient (length alist) 2) 1))) ;
subtract 1 since list-ref position starts at zero
   (if (odd? (length alist))
       (list-ref alist middle-ref)
       (/ (+ (list-ref sorted-list middle-position)
             (list-ref sorted-list (+ 1 middle-position)))
          2))))

Thanks for any feedback - hopefully I'm not going to ignite a war
about formatting. I just like to see my coding style mature from
beginner to advanced beginner :)

Scott Hickey


Posted on the users mailing list.