"lisp形式"的定义? [英] Definition of "lisp form"?

查看:49
本文介绍了"lisp形式"的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"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".

但是,这(在Scheme中)将不是一种形式:

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).

我可以找到几个有关Lisp表单的不同网站和教程,但没有一个给出完整而详细的定义.我在哪里可以找到一个?

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?

推荐答案

lisp形式是一个lisp数据,它也是一个程序,也就是说,可以无错误地求值.

A lisp form is a lisp datum that is also a program, that is, it can be evaluated without an error.

(3 4 1)

是一个Lisp基准,它是3、4和1的列表.这不是一种形式,但是尝试评估它不会导致另一个基准.而是一个错误.

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.

3

它是一个基准,也是一种形式,也称为正常形式"或自我评估基准",它可以对自身进行求值.

Is a datum, and a form, also called a 'normal form' or a 'self-evaluating datum', it evaluates to itself.

(+ 3 4 1)

复合形式,将其评估为正常形式 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:

(if (oddp 2) (print "me") (print "or me"))

这是一种特殊形式,因为它的头是语法,而不是过程,过程调用和特殊形式之间的 only 区别在于过程调用将形式的所有参数视为形式本身并尝试首先对其进行评估,而特殊形式不一定会这样做.据我们了解,只有这种复合形式的第二个和第四个成员被求值,第一个成员是语法,在这种情况下第三个成员被丢弃.例如我们所知道的:

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:

((a 1) (b 2))

不是Common Lisp中的表单,可以在Scheme中是有效的表单,但仅当表单(a 1)计算为过程数据时才有效.所以:

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:

(let ((a 1) (b 2)) (+ a b))

特殊格式,它不评估其第二个成员,并且以不同于非特殊形式的预期方式评估其第三个成员.即,a和b作为其第三形式的子形式具有不同的绑定.在这种情况下,let是表示特殊形式的句法关键字.

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:

(func arg1 #'let)

同样是错误:

(funcall let ((a 1) (b 2)) (+ a b))

是错误,表明它与过程调用不同.

Is an error, showing that it's different to a procedure call.

这篇关于"lisp形式"的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆