[plt-scheme] Understanding lambda

From: Grant Rettke (grettke at acm.org)
Date: Fri Feb 13 15:34:02 EST 2009

On Fri, Feb 13, 2009 at 2: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.

1. When you evaluate lambda it creates an object which is a procedure
that binds the operand to x and then triples it and adds 5: (lambda
(x) (+ (* 3 x) 5)). If you evaluate that in the repl you will see that
a function object got created.
2. When you say (define f (lambda (x) (+ (* 3 x) 5))) you are saying
that "f" is name which is bound to a location, and that location has a
value, and the value is the function object that you just created.

When you ask if f is equal to the function object you just created, no
it can't be; because f is just a name bound to a location that stores
a value.

To your second point, the value stored in the location to which f is
bound will only change if you do so intentionally, because whey you
say (f 1) you are really just applying 1 to the function object stored
in the value of the location referred to by f.

Posted on the users mailing list.