shorthand for ((lambda () ))

950 views Asked by At

Is there a shorthand in scheme for ((lambda () ))

For example, instead of

((lambda ()
    (define x 1)
    (display x)))

I would love to be able to do something like

(empty-lambda
    (define x 1)
    (display x))
4

There are 4 answers

1
Eli Barzilay On BEST ANSWER

The usual idiom for that is

(let ()
  (define x 1)
  (display x))

which you can of course turn into a quick macro:

(define-syntax-rule (block E ...) (let () E ...))
1
user448810 On
(define-syntax empty-lambda
  (syntax-rules ()
    ((empty-lambda body ...)
      ((lambda () body ...)))))
0
Sam Tobin-Hochstadt On

Racket provides the block form, which works like this:

#lang racket
(require racket/block)
(block
 (define x 1)
 (display x))
0
newacct On

Why not just

(let
    ((x 1))
    (display x))