Definition of “lisp form”?

老子叫甜甜 提交于 2019-11-29 20:27:18

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

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

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:

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

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

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

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)

Is an error, likewise:

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

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

From the common lisp hyperspec glossary

form n. 1. any object meant to be evaluated. 2. a symbol, a compound form, or a self-evaluating object. 3. (for an operator, as in <<operator>> form'') a compound form having that operator as its first element.A quote form is a constant form.''

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!