Of what use is 'lambda'???

Tom Krehbiel tom.krehbiel at motorola.com
Wed Oct 11 15:36:28 EDT 2000


Its been a long time since I worked with lisp, but my memory is that
the deference between define and lambda is the closer. I thought
define created a closer and lambda didn't, which means there is
a significant difference. The lambda command lets you save
pieces of code that you want to use in-line while define performs
a call and its associated overhead.
--Tom K.

"Steven D. Majewski" wrote:

> On Thu, 21 Sep 2000, Kragen Sitaker wrote:
>
> >
> > Unfortunately, although you can use the same syntax, it doesn't always
> > work the same.  In SCM, this code works at the top level, but breaks
> > inside a function:
> >
> > (define (adder x) (lambda (y) (+ x y)))
> > (define adder5 (adder 5))
> > (define adder6 (adder 6))
> > (adder5 (adder6 x))
> >
> > It says:
> >
> > unbound variable:  adder
> > ; in expression: (... adder 5)
> > ; in scope:
> > ;   (adder adder5 adder6 . #@define)
> > ;   (x)
> > ;Evaluation took 0 mSec (0 in gc) 49 cells work, 5 env, 213 bytes other
> >
>
> When I copy those lines into scm, I get:
>
> ERROR: unbound variable:  x
> ; in expression: (... x)
> ; in top level environment.
>
> which is just what I expect as "x" hasn't been defined.
> If I do "(adder5 (adder6 1))" , I get "12" , as expected.
>
> ---|  Steven D. Majewski   (804-982-0831)  <sdm7g at Virginia.EDU>  |---
> ---|  Department of Molecular Physiology and Biological Physics  |---
> ---|  University of Virginia             Health Sciences Center  |---
> ---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---
>                 "All operating systems want to be unix,
>                  All programming languages want to be lisp."




More information about the Python-list mailing list