Hey 👋

Which one do you write ?

· · Web · 4 · 6 · 1

@redstarfish Yeah I was too lazy to add the body haha 😅

@jeko IMO the syntactic sugar of option 1 provides some extra intuition for users who aren't particularly scheme-y.

Although I'm not against the second option. Actually at one point I made a habit out of using it for a while. It's alright!

@MutoShack I did force me to use 2️⃣ and then I stopped. haha

@jeko The second form is useful whenn you are defining the var to the result of an expression, such as a lexical let form. Otherwise use the first form.

you mean this :

(define (hello)
(lambda ()
(let ([bind ing])
(some things))))

instead of this :?

(define (hello)
(let ([bind ing])
(some things)))


That’s not quite what I mean.

Instead, sometimes you do this:

(define hello (let ((bind ing)) (lambda () (some things))))

This is called a lexical closure and it means that “bind” is going to be remembered by different calls to (hello) so you can do this:

(define ing 0) (define hello (let ((bind ing)) (lambda () (set! bind (+ 1 bind)) bind))) (hello) (hello) (hello)

Another situation is when you have a procedure that generates procedures:

(define ((adder x) y) (+ x y)) (define add4 (adder 4)) (define add5 (adder 4))


And of course when you’re defining a thing that isn’t even a procedure:

(define path "/tmp/great-path/") (define list-of-mostly-threes '(3 3 3 0 3))

But 99% of the time just use the normal (define (hello) (some things))

Inscrivez-vous pour prendre part à la conversation

Le réseau social de l'avenir : Pas d'annonces, pas de surveillance institutionnelle, conception éthique et décentralisation ! Possédez vos données avec Mastodon !