Are Lisp forms and Lisp expressions same thing?

后端 未结 3 833
别跟我提以往
别跟我提以往 2021-02-07 04:19

Some literature say \"the first subform of the following form...\" or \"to evaluate a form...\" while some other literature say \"To evaluate an expression...\", and most litera

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-07 05:21

    The definitions and uses of these terms vary by Lisp dialect and community, so there is no clear answer to your question for Lisps in general.

    For their use in Common Lisp, see Rainers detailed answer. To give a short summary:

    The HyperSpec entry for form:

    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 <> form'') a compound form having that operator as its first element.A quote form is a constant form.''

    The HyperSpec entry for expression:

    expression n. 1. an object, often used to emphasize the use of the object to encode or represent information in a specialized format, such as program text. The second expression in a let form is a list of bindings.'' 2. the textual notation used to notate an object in a source file.The expression 'sample is equivalent to (quote sample).''

    So, according to the HyperSpec, expression is used for the (textual) representation, while form is used for Lisp objects to be evaluated. But, as I said above, this is only the definition of those terms in the context of the HyperSpec (and thus Common Lisp).

    In Scheme, however, the R5RS doesn't mention form at all, and talks about expressions only. The R6RS even gives a definition that almost sounds like the exact opposite of the above:

    At the purely syntactical level, both are forms, and form is the general name for a syntactic part of a Scheme program.

    (Talking about the difference between (define …) and (* …).)

提交回复
热议问题