我可以在body中间定义一个变量吗?
Can I define a variable in the middle of a body?
当define
不在程序的最外层时,define
可以出现在body的中间吗?例如:
(define (f x)
(display x)
(define n 1) ; <- Is this allowed?
(+ n x))
或者内部 define
必须始终出现在 body 的开头?例如:
(define (f x)
(define n 1) ; <-
(display x)
(+ n x))
定义必须在函数体的开头。来自 R7RS 的第 5.3.2 节:
5.3.2. Internal definitions
Definitions can occur at the beginning of a <body> (that
is, the body of a lambda
, let
, let*
, letrec
, letrec*
,
let-values
, let*-values
, let-syntax
, letrec-syntax
,
parameterize
, guard
, or case-lambda
). Note that such a
body might not be apparent until after expansion of other
syntax. Such definitions are known as internal definitions
as opposed to the global definitions described above.
当define
不在程序的最外层时,define
可以出现在body的中间吗?例如:
(define (f x)
(display x)
(define n 1) ; <- Is this allowed?
(+ n x))
或者内部 define
必须始终出现在 body 的开头?例如:
(define (f x)
(define n 1) ; <-
(display x)
(+ n x))
定义必须在函数体的开头。来自 R7RS 的第 5.3.2 节:
5.3.2. Internal definitions
Definitions can occur at the beginning of a <body> (that is, the body of alambda
,let
,let*
,letrec
,letrec*
,let-values
,let*-values
,let-syntax
,letrec-syntax
,parameterize
,guard
, orcase-lambda
). Note that such a body might not be apparent until after expansion of other syntax. Such definitions are known as internal definitions as opposed to the global definitions described above.