tags:

views:

220

answers:

2

Hi,

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?

+10  A: 

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

Pete Kirkham
+12  A: 

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.

Lajla