((lambda () )) 的方案中是否有简写
例如,而不是
((lambda ()
(define x 1)
(display x)))
我希望能够做类似的事情
(empty-lambda
(define x 1)
(display x))
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 ...))
为什么不只是
(let
((x 1))
(display x))
Racket 提供了block
表单,其工作方式如下:
#lang racket
(require racket/block)
(block
(define x 1)
(display x))
(define-syntax empty-lambda
(syntax-rules ()
((empty-lambda body ...)
((lambda () body ...)))))