Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '(at': 0.04; 'syntax': 0.04; 'python)': 0.05; 'indexing': 0.07; 'subject:PEP': 0.07; 'welcome.': 0.07; 'badly': 0.09; 'check,': 0.09; 'says.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "'break'": 0.16; "'for',": 0.16; '(note:': 0.16; 'true:': 0.16; 'language': 0.16; 'wrote:': 0.18; 'possible,': 0.19; 'portion': 0.22; 'cc:addr:python.org': 0.22; 'accommodate': 0.24; 'effort.': 0.24; "shouldn't": 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In- Reply-To:1': 0.27; "doesn't": 0.30; 'said,': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'gives': 0.31; 'code': 0.31; 'comments': 0.31; 'argue': 0.31; 'motivation': 0.31; 'themselves': 0.32; 'run': 0.32; 'sense': 0.34; 'could': 0.34; 'convert': 0.35; 'etc.)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'much.': 0.36; 'skip:f 40': 0.36; 'possible': 0.36; 'too': 0.37; 'being': 0.38; 'aspects': 0.39; 'bad': 0.39; 'itself': 0.39; 'sure': 0.39; 'ian': 0.60; 'subject:? ': 0.60; 'affect': 0.61; 'course': 0.61; 'making': 0.63; 'act': 0.63; 'name': 0.63; 'real': 0.63; 'teaching': 0.64; 'more': 0.64; 'great': 0.65; 'to:addr:aol.com': 0.68; 'overall': 0.69; 'as:': 0.81; 'subject:this': 0.83; "'and'": 0.84; "'for'": 0.84; 'concept.': 0.84; 'costs,': 0.91; 'taught': 0.96; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3G7oJYmePI/GXElf1QbPz6KD6FdMYq9+uYnenSXRC9c=; b=hYUgsYJirEUxA7lIM9mT+WQu33FFU7RO4UEVWNyShKJ2wsf/+1pz5FFF8QbJtWG1xA 6zTgT/+m4SONl+ku6h3uhzZI2uAur8yzjuztwag9meviHVxTE0oRL02qZjNVgpaDO6U/ R9zLhRqkcwYDakIRW1i7ra4gfeC1nZ8MdZW/pK3KM7ATIBAMhDi0HjQkC7Sw5qlk5BOt 6j1UHG/wGkOSgnzrdMcpYOfl73+tyiN4XdOlJMveOOwVzF65DOhThGTwRylm/dBODTmT O2V8hsqcTotvnaznHTMNgK0finDG7Ko5gM+99QvI6IzwxmByvOq0FQUWmYr+jc6xZCWX YpeQ== X-Received: by 10.152.45.65 with SMTP id k1mr12140278lam.78.1372106487675; Mon, 24 Jun 2013 13:41:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> References: <8D03F2B8CF0E7BE-1864-1796B@webmail-m103.sysops.aol.com> From: Joshua Landau Date: Mon, 24 Jun 2013 21:40:47 +0100 Subject: Re: Is this PEP-able? fwhile To: jimjhb@aol.com Content-Type: text/plain; charset=UTF-8 Cc: python-list 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1372106489 news.xs4all.nl 16002 [2001:888:2000:d::a6]:59034 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:49081 On 24 June 2013 20:52, wrote: > Syntax: > > fwhile X in ListY and conditionZ: > > The following would actually exactly as: for X in ListY: > > fwhile X in ListY and True: > > fwhile would act much like 'for', but would stop if the condition after the > 'and' is no longer True. > > The motivation is to be able to make use of all the great aspects of the > python 'for' (no indexing or explict > end condition check, etc.) and at the same time avoiding a 'break' from the > 'for'. There is one good reason not to use breaks: itertools. I often prefer a for-over-a-properly-constrained-iterable to a for-with-a-break, but there's no real reason to ever prefer a while. That said, why add this to the syntax when there's already functionality that gives you what you want? Just use itertools.takewhile as Ian Kelly says. > (NOTE: Many people are being taught to avoid 'break' and 'continue' at all > costs, so they instead convert > the clean 'for' into a less-clean 'while'. Or they just let the 'for' run > out. You can argue against this teaching > (at least for Python) but that doesn't mean it's not prevalent and > prevailing.) We shouldn't make a language around "people are taught the language badly - let us accommodate for their bad practices!" > [People who avoid the 'break' by functionalizing an inner portion of the > loop are just kidding themselves and making > their own code worse, IMO.] > > I'm not super familiar with CPython, but I'm pretty sure I could get this up > and working without too much effort. > The mandatory 'and' makes sense because 'or' would hold the end value valid > (weird) and not accomplish much. > The condition itself could of course have multiple parts to it, including > 'or's. > > It's possible the name 'fwhile' is not optimal, but that shouldn't affect > the overall merit/non-merit of the concept. "Possible"? It's more than just possible, *wink*. > Comments and Questions welcome.