Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'languages,': 0.04; 'languages.': 0.04; 'argument': 0.05; 'guido': 0.05; 'subject:Python': 0.06; 'problem?': 0.07; 'bindings': 0.09; 'deprecated': 0.09; 'oh,': 0.09; 'otherwise)': 0.09; 'pep': 0.09; 'so?': 0.09; 'subject:language': 0.09; 'worse': 0.09; 'python': 0.11; 'language,': 0.12; 'language.': 0.14; '"lambda"': 0.16; '"mark': 0.16; '>>': 0.16; '*less*': 0.16; '23,': 0.16; 'constructs': 0.16; 'expects': 0.16; "guido's": 0.16; 'lambda': 0.16; 'lie': 0.16; 'likewise': 0.16; 'merely': 0.16; 'scientists': 0.16; 'subject: \n ': 0.16; 'surprising': 0.16; 'two,': 0.16; 'url:thread': 0.16; 'url:weblogs': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; "python's": 0.19; 'slightly': 0.19; 'things.': 0.19; '>>>': 0.22; 'programming': 0.22; 'email addr:gmail.com>': 0.22; '>>>': 0.24; '(by': 0.24; 'either.': 0.24; 'rid': 0.24; 'tend': 0.24; 'question': 0.24; "i've": 0.25; '>': 0.26; 'suggested': 0.26; 'post': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'am,': 0.29; "doesn't": 0.30; 'primarily': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'that.': 0.31; '(maybe': 0.31; 'anonymous': 0.31; "d'aprano": 0.31; 'follows': 0.31; 'purely': 0.31; 'steven': 0.31; 'languages': 0.32; 'another': 0.32; 'everyone': 0.33; 'fri,': 0.33; 'style': 0.33; 'totally': 0.33; 'could': 0.34; 'problem': 0.35; 'knowledge': 0.35; "can't": 0.35; 'agree': 0.35; 'knows': 0.35; 'anybody': 0.35; 'one,': 0.35; 'point.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'keyword': 0.36; 'useful': 0.36; 'wrong': 0.37; 'being': 0.38; 'skip:& 10': 0.38; 'filter': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'expect': 0.39; 'does': 0.39; "couldn't": 0.39; 'functional': 0.39; 'generating': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'users': 0.40; 'how': 0.40; 'remove': 0.60; 'skip:u 10': 0.60; 'read': 0.60; 'then,': 0.60; 'most': 0.60; 'hope': 0.61; 'gone': 0.61; "you're": 0.61; 'map': 0.64; 'more': 0.64; 'mar': 0.68; 'anything.': 0.68; 'nobody': 0.68; 'url:jsp': 0.68; 'fact,': 0.69; 'to,': 0.72; 'other.': 0.75; 'glad': 0.83; 'subject:this': 0.83; '(according': 0.84; 'asked.': 0.84; 'assessment,': 0.84; 'break.': 0.84; 'confusing': 0.84; 'confusion.': 0.84; 'different.': 0.84; 'hard.': 0.84; '\xa0one': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Tv7ts4STLG0ens56ViwqKSZVxJcnGXCgHN5W+XJAvFE=; b=ePhqBtrQBPYJh25hgaTdHB9OCe2TemNhkAZWHlV9Issu4wS53pO64nB8RV8QUs4FjJ LhTshbnRKovSYE/h9fwFb2OQhfFCp5ocDwP91d7v2LBPgN/scZfpAO2L9L5+524D0Sg/ IjfZ1CS1IppjwqZG0kHJQGyKhLZBpfG7op/d/2LtY19BU1PIB5w+kATkGUG4+slzzbeH q1II1TKyWE7WPbCiA6q754iDkd2OOGhNFjfm49SLCIJSnVyK6iyFLdAWTzTlc7nEIuiR 6H04mABCHjYaiNIvQ9NqzNxub6An2oeNSSMCTXtHavoOHxuU0YYnbeKkzXyl6wqcXqgu 8eag== MIME-Version: 1.0 X-Received: by 10.66.66.66 with SMTP id d2mr70438025pat.80.1395651792337; Mon, 24 Mar 2014 02:03:12 -0700 (PDT) In-Reply-To: References: <9daf0806-02de-4447-964c-c8f8953c23e5@googlegroups.com> <10101874-2995-4acd-9851-989603f052e3@googlegroups.com> <532d5bd9$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 24 Mar 2014 03:03:12 -0600 Subject: Re: Explanation of this Python language feature? [x for x in x for x in x] (to flatten a nested list) From: Ian Kelly To: Python Content-Type: multipart/alternative; boundary=001a113628f450002f04f55681ee X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 167 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1395651801 news.xs4all.nl 2867 [2001:888:2000:d::a6]:40804 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:68855 --001a113628f450002f04f55681ee Content-Type: text/plain; charset=ISO-8859-1 On Mar 23, 2014 11:56 PM, "Mark H Harris" wrote: > > On 3/22/14 4:46 AM, Steven D'Aprano wrote: >> >> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote: >> >>> Lambda is a problem, if only because it causes confusion. What's the >>> problem? Glad you asked. The constructs DO NOT work the way most people >>> would expect them to, having limited knowledge of python! > > > One of the best links for understanding what is wrong with lambda is here, from Guido, (by the way I agree totally with his assessment, there is no point really in writing it out again): > > http://www.artima.com/weblogs/viewpost.jsp?thread=98196 That post doesn't point out anything "wrong" with lambda. The argument boils down to: 1) map and filter are not useful because we have comprehensions; 2) reduce is confusing; 3) if we remove those then lambda is not useful either. > Lambda is a problem of confusion for scientists and other mathematicians (amateur and otherwise) who may be confused because python's lambda does not do precisely what they might expect from other functional programming languages, nor does it match precisely with the lambda calculus. Its also confusing to sophisticated users of all stripes who may not be aware of "lambda" at all. The difference does not really lie in the lambda construct per se but in the binding style of closures. Functional languages tend to go one way here; imperative languages tend to go the other. Python being primarily an imperative language follows the imperative model. Anonymous functions in Python work the same way in this regard as anonymous functions in Lua or ECMAScript or Go -- those other languages merely avoid the cardinal sin of defining their anonymous functions using the keyword "lambda". The result may be more surprising to users accustomed to functional languages, but I claim that it is *less* surprising to users of other imperative languages. >> Python is not a pure functional language, but you can write functional >> code in it. If you want a pure functional language, you know where to >> find one. > > > Yes, that's obvious; but you're missing the point. Python is not a functional language, and implying that it can be used as one is misleading at best (maybe a lie at worst) just because it has a construct for generating a dynamic anonymous function. Oh, give me a break. If you find that you can't write functional code in Python just because closure bindings are slightly inconvenient, then you can't be trying very hard. > Well, number one, I'm not demanding anything. Number two, everyone who uses Haskell (for whatever reason) knows well from the start that its a pure functional programming language. That is the advertisement, and that is the expectation. No one expects anything different. And I would hope that anybody who uses Python is likewise aware from the stay that it *isn't* a purely functional language. >> Python could deprecate many things. It would make Python a worse language. > > > How so? Read Guido's argument above. Another way to answer this question is that I have been programming with Python for almost a decade and I've not used lambda. In fact, I have gone out of my way to NOT use lambda because I am fully aware that the BDFL hates it. If lambda were going to be deprecated and removed then it already would have happened in Python 3, because Guido tried to do precisely that. I'm not sure what the reasons were for keeping it in the end (according to PEP 3099 it was because nobody suggested a suitable replacement), but if he couldn't get rid of it then, he never will. --001a113628f450002f04f55681ee Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Mar 23, 2014 11:56 PM, "Mark H Harris" <harrismh777@gmail.com> wrote:
>
> On 3/22/14 4:46 AM, Steven D'Aprano wrote:
>>
>> On Fri, 21 Mar 2014 23:51:38 -0500, Mark H Harris wrote:
>>
>>> Lambda is a problem, if only because it causes confusion. What= 's the
>>> problem? =A0Glad you asked. The constructs DO NOT work the way= most people
>>> would expect them to, having limited knowledge of python!
>
>
> =A0 =A0One of the best links for understanding what is wrong with lamb= da is here, from Guido, (by the way I agree totally with his assessment, th= ere is no point really in writing it out again):
>
> =A0 http://www.artima.com/weblogs/viewpost.jsp?thread=3D98196

That post doesn't point out anything "wrong" w= ith lambda. The argument boils down to: 1) map and filter are not useful be= cause we have comprehensions; 2) reduce is confusing; 3) if we remove those= then lambda is not useful either.

> Lambda is a problem of confusion for scientists and oth= er mathematicians (amateur and otherwise) who may be confused because pytho= n's lambda does not do precisely what they might expect from other func= tional programming languages, nor does it match precisely with the lambda c= alculus. Its also confusing to sophisticated users of all stripes who may n= ot be aware of "lambda" at all.

The difference does not really lie in the lambda construct p= er se but in the binding style of closures. Functional languages tend to go= one way here; imperative languages tend to go the other. Python being prim= arily an imperative language follows the imperative model. Anonymous functi= ons in Python work the same way in this regard as anonymous functions in Lu= a or ECMAScript or Go -- those other languages merely avoid the cardinal si= n of defining their anonymous functions using the keyword "lambda"= ;. The result may be more surprising to users accustomed to functional lang= uages, but I claim that it is *less* surprising to users of other imperativ= e languages.

>> Python is not a pure functional language, but you c= an write functional
>> code in it. If you want a pure functional language, you know where= to
>> find one.
>
>
> =A0 =A0Yes, that's obvious; but you're missing the point. Pyth= on is not a functional language, and implying that it can be used as one is= misleading at best (maybe a lie at worst) just because it has a construct = for generating a dynamic anonymous function.

Oh, give me a break. If you find that you can't write fu= nctional code in Python just because closure bindings are slightly inconven= ient, then you can't be trying very hard.

> =A0 =A0Well, number one, I'm not demanding anything= . Number two, everyone who uses Haskell (for whatever reason) knows well fr= om the start that its a pure functional programming language. That is the a= dvertisement, and that is the expectation. No one expects anything differen= t.

And I would hope that anybody who uses Python is likewise aw= are from the stay that it *isn't* a purely functional language.

>> Python could deprecate many things. It would make P= ython a worse language.
>
>
> =A0 =A0How so? =A0Read Guido's argument above. Another way to answ= er this question is that I have been programming with Python for almost a d= ecade and I've not used lambda. In fact, I have gone out of my way to N= OT use lambda because I am fully aware that the BDFL hates it.

If lambda were going to be deprecated and removed then it al= ready would have happened in Python 3, because Guido tried to do precisely = that. I'm not sure what the reasons were for keeping it in the end (acc= ording to PEP 3099 it was because nobody suggested a suitable replacement),= but if he couldn't get rid of it then, he never will.

--001a113628f450002f04f55681ee--