[racket] Why internal definitions?
That is not an internal definition. This is an internal definition:
(define (foo x)
(define i 10)
(define j 12)
(+ x i j))
It is preferred because there is no right-ward shift and it unifies the
top-level more with local definition contexts---which in my mind is good
for understanding and copy/pasting it.
The only reason you wouldn't like it, IMHO, is when you would use a let*
that re-binds:
(let* ([x 2] [x (+ x 4)] ...)
!=
(define x 2) (define x (+ x 4)) ...
It would be nice if we had a define* like define-package has.
Jay
On Tue, Nov 15, 2011 at 9:50 PM, Jordan Schatz <jordan at noionlabs.com> wrote:
> From Racket v5.2 release notes:
>
> > Internal-definition expansion has changed to use let* semantics for
> > sequences that contain no back references. This change removes a
> > performance penalty for using internal definitions instead of let in
> > common cases, and it only changes the meaning of programs that capture
> > continuations in internal definitions. Internal definitions are now
> > considered preferable in style to let.
>
> I'm not sure that I understand, but if I have it figured out then this:
>
> (define (foo x)
> (local [(define i 10)
> (define j 12)]
> (+ x i j)))
>
> Is now considered better style then this?
>
> (define (foo2 x)
> (let ([i 10]
> [j 12])
> (+ x i j)))
>
> Why?
>
> Shalom,
> Jordan
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users
>
--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay
"The glory of God is Intelligence" - D&C 93
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111115/dd80e05d/attachment.html>