Lambda Functions

An expression (lambda args code) is a way of producing an anonymous procedure (one without a name). In fact, the following do the same thing:


(define (sum x y) (+ x y))
(define sum (lambda (x y) (+ x y)))

A lambda expression can be used as a procedure:


> ((lambda (x) (+ x x)) 4)
8

lambda expressions are especially useful with functions such as map:


> (map (lambda (x) (+ x 2)) '(1 2 3))
(3 4 5)

> (some odd? '(a b 2 3)) *** ERROR -- INTEGER expected

> (some (lambda (x) (and (integer? x) (odd? x))) '(a b 2 3)) #t

Contents    Page-10    Prev    Next    Page+10    Index