[Edu-sig] Re: [Tutor] Thoughts on little lambda

Kirby Urner urnerk@qwest.net
Mon, 11 Mar 2002 10:58:30 -0800


You make an excellent point Jeff.  It wasn't clear to me
at first that I was moving towards such a simple lambda,
so simple, in fact, that we don't need it at all.

So the template should be revised as you've indicated:

    def builder(B_arg1,B_arg2...):
       def main(E_args):
           # statements using B_arg1,B_arg2
       return main # expecting E_args as inputs

So take all of my earlier templates and make this
change of 'return lambda x: main(x)' --> 'return main'

Thanks for the insight!

Next question:  Is there a way to associate a customized
doc string with the built function?

Kirby


>Recently, Kirby Urner described a bit about the differences between 
>Python's lambda and Lisp-ish
>lambdas.  To create something that works a bit more like the Lisp-ish 
>lambda, Kirby proposed using a
>function factory like this:
>
>
> >     def funcfact(r,j):
> >         def main(x):
> >            if not x%2:
> >               return pow(x,j)+4
> >            else:
> >               return pow(x,r)+3
> >         return lambda x: main(x)
>
>Now, I might be missing something (wouldn't be the first time ;) ) but it 
>seems to me that the return
>statement doesn't need to create a lambda;  it should be equivalent to 
>change it to simply
>
>             return main
>
>shouldn't it?  ISTM that the lambda here creates a function object that 
>calls a function, using
>exactly the arguments passed to it;  I see no benefit to encapsulating 
>that second function object
>(the main in the above example) inside of another function object (and 
>some cost in terms of
>overhead).
>
>Jeff Shannon
>Technician/Programmer
>Credit International