Re: [Python-ideas] Multi Statement Lambdas

2018-10-28 Thread Vladimir Filipović
On Tue, Oct 23, 2018 at 1:16 PM Chris Angelico wrote: > a lambda function should be treated as a block of code > inside another function, and not as its own entity. You don't give a > name to the block of code between "if" and "else" ... Very well put! Thanks. > Currently, lambda functions are

Re: [Python-ideas] Multi Statement Lambdas

2018-10-23 Thread Chris Angelico
On Tue, Oct 23, 2018 at 8:04 PM Vladimir Filipović wrote: > > Chris, I'm happy to work with you to hammer out comparisons of various > solutions. > > But I can't take on the role of an advocate for "multi-statement lambdas". I > don't even understand what precisely that covers, since we don't ha

Re: [Python-ideas] Multi Statement Lambdas

2018-10-23 Thread Vladimir Filipović
Chris, I'm happy to work with you to hammer out comparisons of various solutions. But I can't take on the role of an advocate for "multi-statement lambdas". I don't even understand what precisely that covers, since we don't have uni-statement lambdas. _If that role would be needed for this discuss

Re: [Python-ideas] Multi Statement Lambdas

2018-10-22 Thread Serhiy Storchaka
22.10.18 02:16, Terry Reedy пише: All functions created from lambda expressions get the same pseudo-name ''.  This can make tracebacks worse.  Perhaps more importantly, proper testing may become harder. See https://bugs.python.org/issue34856. But this can work only while lambda's body is a s

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 11:40 AM Steven D'Aprano wrote: > > On Mon, Oct 22, 2018 at 10:25:19AM +1100, Chris Angelico wrote: > > On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > > > Except for relatively trivial expressions, this is a bad thing. All > > > functions created from lambda expr

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Mon, Oct 22, 2018 at 10:25:19AM +1100, Chris Angelico wrote: > On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > Except for relatively trivial expressions, this is a bad thing. All > > functions created from lambda expressions get the same pseudo-name > > ''. This can make tracebacks w

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 10:16 AM Terry Reedy wrote: > > On 10/21/2018 12:28 PM, Andreas Winschu wrote > > > A def function has to be named. > > In general, this is a good thing. It often improves tracebacks. > Perhaps more importantly, name facilitate testing and mocking. > > > Wheres a lambda ex

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 8:05 AM Vladimir Filipović wrote: > From one popular library: > > ws = websocket.WebSocketApp( > url, > on_open = (lambda ws: ws.send('subscribe'); conn_counter += 1), > on_message = (lambda ws, msg: print(msg); msg_counter += 1)) > > Because they include statem

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Vladimir Filipović
On Mon, Oct 22, 2018 at 12:52 AM Steven D'Aprano wrote: > > def inc_counter(): > > counter += 1 > > I don't think that's a real working example. > ... > You need to declare counter and sum as global variables. Good catch! None of the examples were real, in the sense of being copied directly f

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Terry Reedy
On 10/21/2018 12:28 PM, Andreas Winschu wrote A def function has to be named. In general, this is a good thing. It often improves tracebacks. Perhaps more importantly, name facilitate testing and mocking. Wheres a lambda expression can be passed anonymously to any other function as an arg

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Sun, Oct 21, 2018 at 06:28:40PM +0200, Andreas Winschu wrote: > A def function has to be named. That's a feature, not a lack. As a general rule of thumb, if the body of a function is complex enough to require multiple statements, it is probably complex enough to require documentation, testi

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Steven D'Aprano
On Sun, Oct 21, 2018 at 11:04:02PM +0200, Vladimir Filipović wrote: > Sometimes I need that callable to be something very simple, but it > technically can't be a lambda because it has a statement in it. > Defining it as a function forces me to give it not only a name, but a > place too. Defining i

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Terry Reedy
On 10/21/2018 12:06 PM, Andreas Winschu wrote: There was an extensive discussion about this in the past. https://www.artima.com/weblogs/viewpost.jsp?thread=147358 And perhaps 20 other threads, now including this one. In the end Guido felt that his effort seems to him like building a Rube Go

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Vladimir Filipović
On Sun, Oct 21, 2018 at 6:39 PM Chris Angelico wrote: > Sure, but can you give examples where you can't use lambda, but still > want it to have no name? I can try kinda answering this: It's less with everyday built-ins and the standard library (though see first example below), and more with libra

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Tobias Kohn
it might just be a detail, but Python does not even have single-statement lambdas.  The body of a lambda is an expression yielding a value, not a statement. Function languages (from which the idea of the Lambda in Python probably came from) do not have statements at all.  Something like th

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Ron Reiter
Just write all your transformations at the top of the file and then write the mapreduce chain at the end. If you need to use closures that depend on each other then it may be a bit more ugly but still feasible to implement. - Ron [image: Facebook] [image: Twi

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Marko Ristin-Kaufmann
Hi, What about writing longer map&reduces in pyspark? When I worked with Spark and Scala, it was easy to script a longer chain of transformations in Scala. Does anybody know how that works in Python without multiline lambdas? Cheers Marko Le dim. 21 oct. 2018 à 18:40, Ron Reiter a écrit : > Mu

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Ron Reiter
Multi-line lambdas may be nice for functional languages, but Python is very imperative in nature and prefers clean syntax over conciseness, which means it will make it REALLY hard to fit with Python. I personally find multi-line lambdas an unreadable abomination. As for some more concrete reasons

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 3:29 AM Andreas Winschu wrote: > > A def function has to be named. > > Wheres a lambda expression can be passed anonymously to any other function as > an argument. > > map(lambda x: x**2, array) > > vs > > def powers2(x) >x**2 > map(powers2, array) > > Coming up with a

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Anders Hovmöller
> Wheres a lambda expression can be passed anonymously to any other function as > an argument. > > map(lambda x: x**2, array) > > vs > > def powers2(x) >x**2 > map(powers2, array) > > Coming up with a name here is not needed, as the operation is expressive > enough. Sure, but there is

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Andreas Winschu
A def function has to be named. Wheres a lambda expression can be passed anonymously to any other function as an argument. *map(lambda x: x**2, array)* vs *def powers2(x)* * x**2* *map(powers2, array)* Coming up with a name here is not needed, as the operation is expressive enough. Am So.

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Anders Hovmöller
> A powerful general purpose language should not limit itself to one statement > in a closure. Nitpick on language: It doesn't. Lambdas are not the only way to do a closure. It's important to be precise when discussing these things. > Lets add mutli-statement lambdas to python either with

Re: [Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Chris Angelico
On Mon, Oct 22, 2018 at 3:07 AM Andreas Winschu wrote: > Guido had a hard opinion on this, but i hope the python community does not. A > powerful general purpose language should not limit itself to one statement in > a closure. > Lets add mutli-statement lambdas to python either with just curly

[Python-ideas] Multi Statement Lambdas

2018-10-21 Thread Andreas Winschu
There was an extensive discussion about this in the past. https://www.artima.com/weblogs/viewpost.jsp?thread=147358 In the end Guido felt that his effort seems to him like building a Rube Goldberg machine. By looking at the amount of people still stumbling on this issue we definitely feel, that