Are Lisp forms and Lisp expressions same thing?

后端 未结 3 822
别跟我提以往
别跟我提以往 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 04:58

    This is by no means a scientific or standards-based answer, but the distinction that I have built up in my own head based on things I've heard is more along the lines of: an expression is a form which will be (or can be) evaluated in the final program.

    So for instance, consider the form (lambda (x) (+ x 1)). It is a list of three elements: the symbol lambda, the list (x), and the list (+ x 1). All of those elements are forms, but only the last is an expression, because it is "intended" for evaluation; the first two forms are shuffled around by the macroexpander but never evaluated. The outermost form (lambda (x) (+ x 1)) is itself an expression as well.

    This seems to me to be an interesting distinction, but it does mean it is context-sensitive: (x) is always a form, and may or may not be an expression depending on context.

提交回复
热议问题