[plt-scheme] Understanding lambda

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Fri Feb 13 15:12:53 EST 2009

On Fri, Feb 13, 2009 at 3:05 PM, aditya shukla
<adityashukla1983 at gmail.com> wrote:
> I am trying to understand lambda and i have a question.
> Suppose (define f (lambda(x) (+(* 3 x) 5)))
> Now i have read and heard that lambda is used to define unnamed functions
> now , i am confused about the value of f
> ie will it be equal to the function returned by (lambda(x) (+(* 3 x) 5)) or
> will be equal to the value which is computed for any value of x ie if x =1
> then f =8.Any help is appreciated.

As you say, lambda is used to define functions without giving them a
name.  The define form, on the other hand, gives things names.  So
(define f (lambda ...)) is just a function with a name.  Hence, your
first hypothesis was correct.

If you inspect your second hypothesis closely, you will see that it
cannot work that way.  You conjecture that the value of f may depend
on the value of x.  However, you have not provided a value for x
yet... so what value does f have?  You've defined it, so it must have
some value.  You have not defined x yet; as x has no value, but f does
have a value, f's value cannot depend on x.

In your definition, f is a function, and that function never changes.
The result of applying that function does change, however, depending
on what value you apply it to.

(f 1) = 8
(f 2) = 11
(f 1000) = 3005

and so on.

I hope this clarifies the matter for you.

Carl Eastlund

Posted on the users mailing list.