To be fair: As a new user, it's possible to have the intuition that `define` is just a way to avoid indentation -- that it "writes a `let` for you, from the point of the define to 'the end of the enclosing scope'".
And it's possible for that intuition to seem correct for a very long time -- until you hit an example like Brian did. And then you need to learn about `letrec`. (As a non-new user, 99.9% of the time that I use a local `define` I actually wish it were "like `let`" not `letrec`, but I use it anyway and try to be careful.) On Mon, Mar 11, 2019 at 12:29 PM Matthias Felleisen <matth...@felleisen.org> wrote: > > > > > On Mar 11, 2019, at 11:21 AM, Brian Adkins <lojicdot...@gmail.com> 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 > > -- > 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. -- 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.