Search code examples
lambdaschemethe-little-schemer

What's the reason for using lambda expressions to define functions in Scheme?


I am reading the The Little Schemer book by Daniel Friedman. I don't understand why every function in the book is written with a lambda expression.

(define fun1
  (lambda (x1 x2)
    (+ x1 x2)))

(define (fun2 x1 x2)
  (+ x2 x2))

The two functions do the same thing, but the second one is neater. I am curious about the reasons to use lambda everywhere.

I used DrRacket in this case.


Solution

  • (define (x . a) ...) 
    

    is just an abbreviation for

    (define x (lambda a ...))
    

    In the very first scheme report from 1975 you didn't have this abbreviation. In the revised report from 1978 it was introduced.

    The little Schemer is just a later edition of The little Lisper from 1974. It predates Scheme and when fixed to follow Scheme they tried to keep is as close to the original as possible. Besides when you use (define x (lambda (arg1) ...)) it's obvious that procedure bindings are not different from other variable bindings other than the object it points to is closure code rather than data.

    If you look at the SICP video lectures you'll see that Abelson and Sussman do have students who are confused with this so it's probably best using only one of these and since anonymous procedures are something you need to touch eventually it's obvious you want to teach the form with a explicit lambda instead of the syntactic sugar.