(define (add x y) (+ x y)) 和 (define add (lambda (x y) (+ x y))) 有什么区别?

what is difference between (define (add x y) (+ x y)) and (define add (lambda (x y) (+ x y)))?

我现在正在使用 C++ 编写方案的解释器。我有一个关于 define 和 lambda 的问题。

(define (add x y) (+ x y))

扩展为

(define add (lambda (x y) (+ x y)))

来自 lispy.py

这两个表达式有什么区别?

为什么要扩展表达式?就因为表达式容易求值?

它们是相同的,因为一个扩展到另一个。第一个表达式更容易书写和阅读;将它扩展到第二个可以简化解释器(你应该欣赏的东西)。

它们在 R5RS 中是等价的:

5.2 Definitions

(define (<variable> <formals>) <body>)

<Formals> should be either a sequence of zero or more variables, or a sequence of one or more variables followed by a space-delimited period and another variable (as in a lambda expression). This form is equivalent to

(define <variable>
  (lambda (<formals>) <body>)).