On Monday, March 11, 2019 at 12:29:40 PM UTC-4, Matthias Felleisen wrote:
>
>
>
> > On Mar 11, 2019, at 11:21 AM, Brian Adkins <lojic...@gmail.com 
> <javascript:>> wrote: 
> > 
> > I just discovered that define will fail at runtime, where let would fail 
> at compile time. Besides helping to keep the indentation level from 
> marching to the right "too much", what are the benefits of define over let? 
> > 
> > --- snip --- 
> > #lang racket 
> > 
> > (define (f n) (+ n 1)) 
> > 
> > (define (foo) 
> >   (define b (f a)) 
> >   (define a 7) 
> >   
> >   b) 
> > 
> > (define (bar) 
> >   (let ([b (f a)] 
> >         [a 7]) 
> > 
> >     b)) 
> > --- snip --- 
>
>
>
> I think your characterization is a bit misleading here. 
>
> In ‘bar’ ‘a’ is not bound, something that Racket (and DrRacket) properly 
> signal at compile time. 
>
> In ‘foo’ ‘a’ *is* bound, because you’ve set up a mutually recursive scope. 
> But, when Racket evaluates (foo) it notices that ‘a’ is bound but 
> uninitialized, which is two different things. 
>
> If you want to compare apples to apples, use a ‘letrec' instead of a ‘let' 
> in ‘bar'. Then you have (1) the same semantics and (2) the same error. 
>
> — Matthias 
>
>
I want let semantics, but I've been using define more because it's 
preferred in the Racket style guide. I don't want the behavior of define 
above, so using letrec to get a runtime error instead of compile time error 
doesn't make sense.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to