[racket] Why internal definitions?
On Wed, Nov 16, 2011 at 10:22 AM, Jordan Schatz <jordan at noionlabs.com> wrote:
>> (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)))
>
Not to be too picky, but these are semantically equivalent. (letrec
would be needed here only if you generalized what was on the
initialization expressions (the 10 and 12). Indeed, the result of
compiling the two expressions above should be identical because the
Racket compiler detects this and avoids the extra work that a
translation to letrec would entail.)
Robby