Re: explain this function to me, lambda confusion

2008-05-20 Thread Arnaud Delobelle
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > Paul McGuire a écrit : >> On May 19, 11:04 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >>> Paul McGuire <[EMAIL PROTECTED]> writes: >>> >>> [...] >>> >>> Could you use it as a decoratore instead? >>> >>> integer = Word("0123456789") >>> >>> @in

Re: explain this function to me, lambda confusion

2008-05-20 Thread Bruno Desthuilliers
Paul McGuire a écrit : On May 19, 11:04 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: Paul McGuire <[EMAIL PROTECTED]> writes: [...] Could you use it as a decoratore instead? integer = Word("0123456789") @integer.setParseAction def parse_integer(tokens): return int(tokens[0]) I could

Re: explain this function to me, lambda confusion

2008-05-19 Thread Arnaud Delobelle
Paul McGuire <[EMAIL PROTECTED]> writes: > On May 19, 11:04 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >> Paul McGuire <[EMAIL PROTECTED]> writes: >> >> [...] >> >> Could you use it as a decoratore instead? >> >> integer = Word("0123456789") >> >> @integer.setParseAction >> def parse_integer(

Re: explain this function to me, lambda confusion

2008-05-19 Thread Paul McGuire
On May 19, 11:04 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > Paul McGuire <[EMAIL PROTECTED]> writes: > > [...] > > Could you use it as a decoratore instead? > > integer = Word("0123456789") > > @integer.setParseAction > def parse_integer(tokens): >     return int(tokens[0]) > > I could make

Re: explain this function to me, lambda confusion

2008-05-19 Thread Arnaud Delobelle
Paul McGuire <[EMAIL PROTECTED]> writes: [...] > lambda is handy in defining parse actions in pyparsing. Parse actions > are callbacks to be run when an expression within a larger grammar is > matched. A common use for parse actions is to do some sort of text or > type conversion. The simplest

Re: explain this function to me, lambda confusion

2008-05-19 Thread Paul McGuire
On May 18, 10:41 am, "inhahe" <[EMAIL PROTECTED]> wrote: > > Both the responses offer lambda free alternatives. That's fine, and > > given the terse documentation and problems that I had understanding > > them, I would agree. So what applications are lambdas suited to? I > > think the parameterised

Re: explain this function to me, lambda confusion

2008-05-19 Thread Terry Reedy
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On May 19, 5:22 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: | > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message | [...] | > | Note that the same thing can be said about generator expressions, | > | which are

Re: explain this function to me, lambda confusion

2008-05-19 Thread Bruno Desthuilliers
inhahe a écrit : Both the responses offer lambda free alternatives. That's fine, and given the terse documentation and problems that I had understanding them, I would agree. So what applications are lambdas suited to? I think the parameterised function model is one. What else? i've hardly ever

Re: explain this function to me, lambda confusion

2008-05-19 Thread Arnaud Delobelle
On May 19, 5:22 am, "Terry Reedy" <[EMAIL PROTECTED]> wrote: > "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message [...] > | Note that the same thing can be said about generator expressions, > | which are nothing more than anonymous, non-reusable, generator > | functions. > > Right. So if some

Re: explain this function to me, lambda confusion

2008-05-18 Thread Terry Reedy
"Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Lie <[EMAIL PROTECTED]> writes: | | > Lambda can actually be safely removed from python and no other | > features would be missing. It is always possible to create a def | > version of any lambda, so lambda is useles

Re: explain this function to me, lambda confusion

2008-05-18 Thread inhahe
> > Both the responses offer lambda free alternatives. That's fine, and > given the terse documentation and problems that I had understanding > them, I would agree. So what applications are lambdas suited to? I > think the parameterised function model is one. > What else? i've hardly ever used lam

Re: explain this function to me, lambda confusion

2008-05-18 Thread Arnaud Delobelle
Lie <[EMAIL PROTECTED]> writes: > Lambda can actually be safely removed from python and no other > features would be missing. It is always possible to create a def > version of any lambda, so lambda is useless. It is just a convenience > for the times where we're just too lazy to invent a name and

Re: explain this function to me, lambda confusion

2008-05-18 Thread Lie
On May 9, 12:12 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 08 May 2008 22:57:03 -0300,   > <[EMAIL PROTECTED]> escribió: > > > > > On May 8, 6:11 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > > >> No, no, no, no, no! > > Geez.  Go easy. > >> You have got it entirely wrong here. Yo

Re: explain this function to me, lambda confusion

2008-05-18 Thread Lie
On May 9, 8:57 am, [EMAIL PROTECTED] wrote: > On May 8, 6:11 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > > > > > No, no, no, no, no! > > Geez.  Go easy. > > > > > You have got it entirely wrong here. Your XOR function simply returns a > > function which gives you the result of xoring the paramete

Re: explain this function to me, lambda confusion

2008-05-09 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > Indeed, there are many ways this could be done. Some are more > concise, some are more efficient. As I said, I did it the way I did > it to try out lambdas. Your way achieves the result, rather elegantly > I think, but teaches me nothing about using lambdas. Unfortun

Re: explain this function to me, lambda confusion

2008-05-08 Thread Gabriel Genellina
En Thu, 08 May 2008 22:57:03 -0300, <[EMAIL PROTECTED]> escribió: On May 8, 6:11 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: No, no, no, no, no! Geez. Go easy. You have got it entirely wrong here. Your XOR function simply [...] Pardon my tetchiness, but it is a little hard to receive su

Re: explain this function to me, lambda confusion

2008-05-08 Thread andrej . panjkov
On May 8, 6:11 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > > No, no, no, no, no! > Geez. Go easy. > You have got it entirely wrong here. Your XOR function simply returns a > function which gives you the result of xoring the parameters AT THE TIME > WHEN YOU ORIGINALLY CREATED IT. I'm guessing

Re: explain this function to me, lambda confusion

2008-05-08 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > Here is a simple lambda that implements an exclusive or: > def XOR(x,y) : return lambda : ( ( x ) and not ( y ) ) or ( not ( x ) and ( y ) ) > > (Because of the resemblance to C macros, I have been cautious and > written the lambda with lots of parentheses

Re: explain this function to me, lambda confusion

2008-05-07 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On May 8, 7:38 am, globalrev <[EMAIL PROTECTED]> wrote: | I would describe a lambda as a parameterised function template. If you | dig, the docs call lambdas anonymous functions not bound to a name. A lambda expression is an abbrevia

Re: explain this function to me, lambda confusion

2008-05-07 Thread andrej . panjkov
On May 8, 10:34 am, [EMAIL PROTECTED] wrote: > > >>> HeightDistrib = (170, 20) > That should be > >>> HeightDistrib = Gaussian(170, 20) -- http://mail.python.org/mailman/listinfo/python-list

Re: explain this function to me, lambda confusion

2008-05-07 Thread andrej . panjkov
On May 8, 7:38 am, globalrev <[EMAIL PROTECTED]> wrote: > i have a rough understanding of lambda but so far only have found use > for it once(in tkinter when passing lambda as an argument i could > circumvent some tricky stuff). > what is the point of the following function? > > def addn(n): >

Re: explain this function to me, lambda confusion

2008-05-07 Thread Gabriel Genellina
En Wed, 07 May 2008 18:38:15 -0300, globalrev <[EMAIL PROTECTED]> escribió: i have a rough understanding of lambda but so far only have found use for it once(in tkinter when passing lambda as an argument i could circumvent some tricky stuff). what is the point of the following function? def a

Re: explain this function to me, lambda confusion

2008-05-07 Thread [EMAIL PROTECTED]
On 7 mai, 23:38, globalrev <[EMAIL PROTECTED]> wrote: > i have a rough understanding of lambda but so far only have found use > for it once(in tkinter when passing lambda as an argument i could > circumvent some tricky stuff). > what is the point of the following function? > > def addn(n): >

Re: explain this function to me, lambda confusion

2008-05-07 Thread globalrev
On 7 Maj, 23:47, globalrev <[EMAIL PROTECTED]> wrote: > and what si the diffrence here: > > g = lambda x=5:x*x > g = lambda x:x*x > > the first was a mistake to write but it worked > and the x=5 seems to be completely ignored. why? it has no effect at > all? ah wait now i see it has a default kind

Re: explain this function to me, lambda confusion

2008-05-07 Thread globalrev
and what si the diffrence here: g = lambda x=5:x*x g = lambda x:x*x the first was a mistake to write but it worked and the x=5 seems to be completely ignored. why? it has no effect at all? -- http://mail.python.org/mailman/listinfo/python-list

explain this function to me, lambda confusion

2008-05-07 Thread globalrev
i have a rough understanding of lambda but so far only have found use for it once(in tkinter when passing lambda as an argument i could circumvent some tricky stuff). what is the point of the following function? def addn(n): return lambda x,inc=n: x+inc if i do addn(5) it returns