Why sharp quote lambda expressions?

前端 未结 4 637
佛祖请我去吃肉
佛祖请我去吃肉 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 07:05

    In short, you don't have to sharp-quote lambda because it is a macro that expands to (function (lambda ...)), and it is function that does all the magic.

    The only sense in which function is not necessary is that you don't have to type it yourself. It is function, not lambda, that is the fundamental operator. Lambda expressions themselves are just ordinary lists (which function knows how to turn into function objects), and lambda is just an ordinary macro. So you've got things rather backwards: that lambda expressions return function objects does not obviate function because lambda is explained in terms of function.

    An additional wrinkle is that in Emacs Lisp, lists that start with lambda can be treated as functions directly, without going through function. This is not the case in CL (although an explicit conversion is available in the form of (coerce some-list 'function)).

提交回复
热议问题