Why sharp quote lambda expressions?

前端 未结 4 651
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 06:32

It is a technique used frequently in On Lisp, which is on Common Lisp:

> (mapcar #\'(lambda (x) (+ x 10))
         \'(1 2 3))
(11 12 13)
4条回答
  •  名媛妹妹
    2021-02-07 06:54

    It all has to do with history. (lambda ...) is just syntactic sugar for #'(lambda ..). Earlier versions of Common Lisp didn't have lambda defined as a macro. Eg. if you read Peter Norvigs essay about Quines (PD, page2) you see he explicitly states you need to create such macro as follows:

    (defmacro lambda (args &body body)
      "Allow (lambda (x) ...) instead of #'(lambda (x) ...)"
      `#'(lambda ,args .,body))
    

    Thus when writing (lambda ...) today a standard macro rewrites it to #'(lambda ...).

    On Lisp is an old book and it may have been first published before the macro became standard. It also may be that Paul Graham is used to write #'(lambda ...) and has stuck with it.

    I've seen that later editions of computer books often change as little as possible when conforming to a newer standard. I'm not sure that is a good thing.

提交回复
热议问题