[racket] Why internal definitions?

From: Jordan Schatz (jordan at noionlabs.com)
Date: Wed Nov 16 11:22:57 EST 2011

> (define (foo x)
>   (define i 10)
>   (define j 12)
>   (+ i j x))
> 
> It's preferable to local defines for aesthetic reasons because it 
> consumes less horizontal space (a smaller indentation). 
So it is really only a matter of style, not semantics/meaning, and the
preference is for:

(define (foo x)
  (define i 10)
  (define j 12)
  (+ i j x))

over

(define (foo x) 
  (let ([i 10]  ;Though to make this semantically the same as the 
        [j 12]) ;above I should use a letrec
    (+ i j x)))

I personally like the let forms, and don't want to repeatedly type
"define", but I still regularly encounter syntax errors where I should
have used a let* or letrec where I had a let, and the local definitions
look alot like C styles languages
$i = 10;
$j = 12; etc.
so they should be easier for my teammates to pick up.

> An *internal* definition differs slightly from a local definition
> in syntax and *semantics*: 
I am pretty new to lisp/scheme so I don't fully understand Shriram's
comments about local being necessary because of scheme's legacy. But it
concerns me that everyone (the release notes, Shriram, Matthias) mention
some difference in meaning between internal defines, letrec, and local,
and I don't see the difference. I feel like a dunce at the moment, but if
there is something subtle that I'm missing, it seems like a good place
for bugs to hid, and somewhere where I will want to enforce a coding
standard so that only one of the forms is used.

Shalom,
Jordan




Posted on the users mailing list.