[Baypiggies] lambda for newbies -- a true newbie question
Stephen McInerney
spmcinerney at hotmail.com
Tue May 15 22:31:24 CEST 2007
Wasn't the question "how will we do this in Python 3000 when lambda is
deprecated?"
Stephen
>From: Kelly Yancey <kelly at nttmcl.com>
>
>Laurence Clark wrote::
> > On 5/11/07, David Berthelot <d_berthelot at yahoo.com> wrote: "I often
> > use it to pass basic functions (that are so basic that keeping them
> > unnamed is perfect) to other functions. If I have to name all those
> > unnamed lambda functions to use them, that's going to be quite
> > verbose, probably a bit too much."
> >
> >
> > Pardon the dumb question, but surely there must be some other way in
> > python to put little anonymous functions into expressions?? Some way
> > to say:
> >
> > my $hundreda = myaddfunction ( sub{return 99;}, 1);
> > my $hundredb = sub{return 99;}->() + 1;
> >
> > Comments anyone?
> >
>
> Perhaps I'm missing the point of your question, but your examples
>aren't that different when expressed in python syntax...
>
> myaddfunction = lambda *args: sum(args)
>
> hundreda = myaddfunction((lambda: 99)() , 1)
> hundredb = (lambda: 99)() + 1
>
> In fact they are slightly more concise than the perl equivalents.
>The key is to use parenthesis to encapsulate the lambda expression (sort
>of like you need brackets in perl to do the same). Then you can call
>the lambda expression just like any other function.
>
> Kelly
>
_________________________________________________________________
More photos, more messages, more storageget 2GB with Windows Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_2G_0507
More information about the Baypiggies
mailing list