ℙℕℤℝ 2010-05-20 19:59
浏览 97
已采纳

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

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?

转载于:https://stackoverflow.com/questions/2877371/definition-of-lisp-form

  • 写回答

2条回答 默认 最新

  • 妄徒之命 2010-05-20 21:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块