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.
Lambda is the name of a special form that generates procedures. It takes some information about the function you want to create as arguments and it returns the procedure. It'll be easier to explain the details after you see an example.
Introduction. Lambda expressions are a new and important feature included in Java SE 8. They provide a clear and concise way to represent one method interface using an expression. Lambda expressions also improve the Collection libraries making it easier to iterate through, filter, and extract data from a Collection .
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With