“Lisp 形式”的定义?
“Lisp 形式”的具体定义是什么?
据我所知,它是“一个原子或一个以符号作为第一个元素的列表”。
但是,这(在Scheme中)不会是一种形式:
((lambda () 42)) ;; The answer to Life, the Universe and Everything.
因为列表的第一个元素本身就是另一个列表。经过评估后,它将成为一个过程(而不是符号)。
我可以找到几个不同的网站和教程讨论 Lisp 形式,但没有一个给出完整而详细的定义。我在哪里可以找到一个?
What exactly the definition of a "Lisp form"?
As far as I know, it's "either an atom or a list that has a symbol as its first element".
But then, this (in Scheme) would not be a form:
((lambda () 42)) ;; The answer to Life, the Universe and Everything.
Because the first element of the list is itself another list. And after it's evaluated it will be a procedure (not a symbol).
I can find several different websites and tutorials talking about Lisp forms, but none which gives a complete and detailed definition. Where can I find one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
lisp 形式是一个 lisp 数据,也是一个程序,也就是说,它可以被无错误地评估。
是一个 Lisp 数据,它是 3、4 和 1 的列表。但这不是一种形式,因为尝试评估它不会产生另一个数据。而是一个错误。
是一个数据,一种形式,也称为“正常形式”或“自评估数据”,它对自身进行评估。
是一种复合形式,对其求值结果为普通形式
8
。除了普通形式和复合形式之外,复合形式还可以细分为过程调用和特殊形式(也称为语法),但更准确地说,特殊形式的头部是语法,如下所示
:特殊形式,因为它的头部是语法,而不是过程,过程调用和特殊形式之间的唯一区别是过程调用将形式的所有参数视为本身的形式,并尝试评估它首先,特殊形式不一定能做到这一点。据我们了解,只有该复合形式的第二个和第四个成员被评估,第一个成员是语法,在这种情况下第三个成员被丢弃。例如,我们知道:
不是 Common Lisp 中的表单,它可能是Scheme 中的有效表单,但前提是表单
(a 1)
计算结果为过程基准。因此:它是一种特殊形式,它不会评估其第二个成员,并以与非特殊形式所预期的方式不同的方式评估其第三个成员。也就是说,a 和 b 作为其第三种形式的子形式具有不同的绑定。在这种情况下,
let
是一个表示特殊形式的语法关键字。请注意,特殊形式很可能仍然评估它们的所有参数,那么它们仍然不是过程调用,因为它们的头是语法,过程可以作为参数传递给其他函数,语法不能,因此:
是一个错误,同样:
是一个错误,表明它与过程调用不同。
A lisp form is a lisp datum that is also a program, that is, it can be evaluated without an error.
Is a lisp datum, it's a list of 3, 4 and 1. This is not a form however as trying to evaluate it does not result into another datum. But rather an error.
Is a datum, and a form, also called a 'normal form' or a 'self-evaluating datum', it evaluates to itself.
Is a compound form, evaluating it results into the normal form
8
.Apart from normal forms and compound forms, compound forms can be subdivided into procedure calls and special forms (also called syntax) but more properly, the head of a special form is the syntax, as in:
This is a special form because it's head is syntax, and not a procedure, the only difference between procedure calls and special forms is that procedure calls see all of the arguments of the form as forms in itself and try to evaluate it first and special forms not necessarily do that. As we understand, only the second and fourth member of this compound form get evaluated, the first member is syntax, and the third is discarded in this case. As we know for instance:
Is not a form in Common Lisp, it could be a valid form in Scheme, but only if the form
(a 1)
evaluates to a procedure datum. So:Is a special form, it does not evaluate its second member, and evaluates its third member in a different fashion than what would be expected if it was not a special form. That is, a and b as subforms of its third form have a different binding.
let
in this case is a syntactic keyword that signals the special form.Note that it's quite possible that special forms still evaluate all of their arguments, they are still not procedure calls then, because their head is syntax, and procedures can be passed to other functions as arguments, syntax cannot, thus:
Is an error, likewise:
Is an error, showing that it's different to a procedure call.
来自 common lisp hyperspec 词汇表
From the common lisp hyperspec glossary