Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'none,': 0.05; 'result,': 0.05; '*args,': 0.07; 'advocate': 0.07; 'arguments': 0.07; 'false,': 0.07; 'ugly': 0.07; 'python': 0.09; '**kwargs)': 0.09; '**kwargs):': 0.09; 'result)': 0.09; 'subject:while': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; ':-)': 0.13; '"while': 0.16; '-tkc': 0.16; 'false:': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'neutral': 0.16; 'none"': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:expression': 0.16; 'syntax.': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'true:': 0.16; 'ugly.': 0.16; 'wrote:': 0.17; 'element': 0.17; 'yield': 0.17; '(or': 0.18; 'mostly': 0.20; 'proposed': 0.20; 'stopping': 0.22; 'cc:2**0': 0.23; "haven't": 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'looks': 0.26; "doesn't": 0.28; "d'aprano": 0.29; 'steven': 0.29; 'time:': 0.29; "i'm": 0.29; 'usually': 0.30; 'initially': 0.30; 'code': 0.31; 'values.': 0.33; 'problem': 0.33; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'test': 0.36; 'should': 0.36; 'too': 0.36; 'previous': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'most': 0.61; 'back': 0.62; 'more': 0.63; 'natural': 0.65; 'results': 0.65; 'disappear': 0.84; 'received:50.22': 0.84; 'upset': 0.84 Date: Sat, 27 Oct 2012 14:15:32 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: while expression feature proposal References: <50886398.5050301@tim.thechases.com> <7x7gqf1na2.fsf@ruckus.brouhaha.com> <508b2858$0$29967$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <508b2858$0$29967$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351365278 news.xs4all.nl 6944 [2001:888:2000:d::a6]:55859 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32289 On 10/26/12 19:18, Steven D'Aprano wrote: > def iterate_until_none_or_false(func, *args, **kwargs): > while True: > x = func(*args, **kwargs) > # Halt if x is None or False, but not other falsey values. > if x is None or x is False: > return > yield x > > for x in iterate_until_none_or_false( > some_function, 1, 2, "c", spam="yummy"): > process(x) I was initially a pretty strong advocate of the proposed "as" syntax. However, the more I've thought about it, the more I keep coming back to how I've solved the problem in the past which is mostly what Steven suggests here. There are so many edge-cases and warts in the "as" syntax; most of which disappear with this generator+forloop: - yielding/unpacking multiple results each time: the "as" syntax would get really ugly. Do you test the whole result, or an element of the result? - knowing the stopping condition varies: is it when something is False-ish (an empty string/tuple/list, False, None, etc)? When it "is None"? When it is exactly "False"? - the whole "x = (foo(bar) as result) if result else None" (or should that be "x = result if (foo(bar) as result) else None"?) style/discussion just really looks ugly to me. Usually I find Python code quite beautiful and this syntax doesn't resonate as "beautiful". To despite my previous excitement, I'm now neutral at best on a limited "while TERM as VAR:" syntax. I know this "being persuaded by rational arguments and changing one's mind" thing is rare on the Intarwebs, so I hope I haven't upset the natural balance of things too greatly. :-) -tkc