The special form lambda
is an anonymous procedure, in the examples shown it's a shorthand to avoid defining a separate one-shot function. For example, the first snippet is equivalent to this:
(define (helper wd)
(word prefix wd))
(define (prepend-every prefix sent)
(every helper sent))
But why define a new procedure that's going to be used only once? that's why we use lambda
in this case. Also, it's good to remember that a function definition written like this:
(define (f x)
<body>)
… Is just a shorter syntax for this equivalent form:
(define f
(lambda (x)
<body>))
So you see, in the end all procedures in Scheme are lambda
s under the hood. There are other special forms that can get transformed to lambda
s, for example let
, let*
, etc. take a look at these posts for further clarification.