Scheme中定义表达式的类型 [英] Type of Define expression in Scheme
问题描述
简单地说:我的问题是Scheme中define表达式的类型是什么?
To put it simply: My question is whats is the type of a define expression in Scheme?
举个例子:
(define x 5)
或
(define x (lambda (n) (* n n)))
这对我来说有点混乱.有人可以帮忙吗?
It's a bit confusing for me. Can anyone help?
推荐答案
In Racket define
是一种特殊形式而不是表达式,所以它本身没有值,如果您尝试执行这样的操作,您会得到一个错误:
In Racket define
is a special form and not an expression, so it doesn't have a value per-se, if you try to execute something like this you'll get an error:
(display (define x 42))
=> define: not allowed in an expression context in: (define x 42)
如果它有一个值,它会类似于 void
,但这将取决于解释器的特定实现细节(我相信我看到一个解释器在 define
之后返回 #t
完成)
If it were to have a value it'd be something akin to void
, but that will be dependent on the particular implementation details of the interpreter (I believe I saw one interpreter return #t
after a define
was completed)
常量 #
被大多数具有副作用且没有有用结果的表单和过程返回
The constant
#<void>
is returned by most forms and procedures that have a side-effect and no useful result
规范不要详细讨论这一点,或者 - 强调它依赖于实现的声明.
The specification doesn't go into details on this point, either - reinforcing the statement that it's implementation-dependent.
这篇关于Scheme中定义表达式的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!