# [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-)

 From: Guillaume Marceau (gmarceau at gmail.com) Date: Tue Jul 26 15:12:41 EDT 2011 Previous message: [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-) Next message: [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-) Messages sorted by: [date] [thread] [subject] [author]

```On 7/21/2011 9:25 AM, Matthias Felleisen wrote:
>
> On Jul 21, 2011, at 6:44 AM, Stephen Bloch wrote:
>
>> Right.  Nested conditionals and loops in Racket are no more syntactically painful than nested conditionals and loops in Java/C/C++, if you put braces around the bodies.
>> ( if (>  x y ) (+ x 3 ) ( * 4 y ) )
>> if ( x>  y ) { x = 3 ; } else { y = 4 ; }
>
>
> You don't have to go non-idiomatic in Racket to approximate
> the non-nesting, step-by-step style of C, Java, and such languages.
>
> Now that define is legal in many places, just give names to
> intermediate results. More generally, here is a conjecture
> about the psychology of programming:
>
>   people take to programming in C more easily than
>   to algebra because they can 'store' intermediate
>   results in 'registers' and take a break to contemplate
>   what to do next.
>
> Warning: this is an untested conjecture by a guy who has 0
> background in psychology or how to conduct an experiment.
> All of this is based on observations.

For what it's worth, my code is formatted this way.

For instance, my code for Cohen's Kappa (
http://en.wikipedia.org/wiki/Cohen%27s_kappa#Calculation ) looks like this:

(define coding-numbers/c (listof (listof number?)))
(define/contract (kappa data)
(coding-numbers/c . -> . number?)

(define choices (remove-duplicates (flatten data)))
(define expected-v
(for/list ([c choices])
(for/list ([person (transpose data)])
(prob-of-v c person))))
(define expected-agreement/choice
(for/list ([c expected-v])
(apply * c)))
(define expected-agreement (apply + expected-agreement/choice))
(if (= 1 expected-agreement)
#f
(/ (- (prob-of-agreement data) expected-agreement)
(- 1 expected-agreement))))

Yes, I always used this style when coding functionally. I'm somewhat
puzzled it's not more popular.

```

 Posted on the users mailing list. Previous message: [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-) Next message: [racket] Sweet expressions; or making it easier to introduce Racket to me and my coworkers :-) Messages sorted by: [date] [thread] [subject] [author]