Search code examples
schemelispsicp

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


I am now writing a scheme's interpreter by using c++. I got a question about define and lambda.

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

is expanded as

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

by lispy.py

what's the difference between this two expression?

why need expand the expression? Just because it is easy to evaluate the expression?


Solution

  • They are the same, since one gets expanded into the other. The first expression is easier to both write & read; having it expand into the second simplifies the interpreter (something you should appreciate).