Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #49232

Re: Is this PEP-able? fwhile

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
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; 'python.': 0.02; 'syntax': 0.04; 'value,': 0.04; 'args': 0.07; 'subject:PEP': 0.07; 'arguments,': 0.09; 'clause': 0.09; 'defines': 0.09; 'executes': 0.09; 'exit': 0.09; 'iterate': 0.09; 'modulo': 0.09; 'operator,': 0.09; 'statements': 0.09; 'variant': 0.09; 'python': 0.11; 'creates': 0.14; '"for"': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'increment': 0.16; 'keyword,': 0.16; 'notation': 0.16; 'notation.': 0.16; 'once.': 0.16; 'optional': 0.16; 'optionally': 0.16; 'superfluous': 0.16; 'syntax,': 0.16; 'syntaxerror:': 0.16; 'true),': 0.16; 'value),': 0.16; 'flexibility': 0.16; 'index': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'basically': 0.19; '>>>': 0.22; 'install': 0.23; 'mind.': 0.24; 'parse': 0.24; 'initial': 0.24; 'script': 0.25; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'wonder': 0.29; 'message-id:@mail.gmail.com': 0.30; 'you?': 0.31; 'block,': 0.31; 'once,': 0.31; 'stands': 0.31; 'there.': 0.32; 'this.': 0.32; 'another': 0.32; "i'd": 0.34; 'could': 0.34; "can't": 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'false': 0.36; 'var': 0.36; 'similar': 0.36; 'two': 0.37; 'step': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'aside': 0.39; 'to:addr:python.org': 0.39; 'subject:? ': 0.60; 'new': 0.61; 'simply': 0.61; 'simple': 0.61; 'back': 0.62; 'more': 0.64; '26,': 0.68; 'invalid': 0.68; 'line,': 0.68; 'safe': 0.72; 'subject:this': 0.83; "'for'": 0.84; 'alone,': 0.84; 'seriously,': 0.84; 'slipped': 0.84; '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:date:message-id:subject:from:to :content-type; bh=14Z81vfpDEV4szj5GKqE6VpbAwD8u9rxPrJG65W1hHw=; b=jnW03xiF9Z2Y7gx1rNs6WZXpCtj3rDFe2HFpbimGhjvUVBOMmtSk2Ojz1RGLGuiWd1 vWX5RlCgesBjxITv3q8Z9CgvP/IkWiKsvbR/whJo1C+B5jwHcNxqbw1HD7IfhaInLK5s nzehBMFOgRB/pwoKvN9lTHmt+uAhP2b+dKGXwXT+/NgAkQztn3r2bsz7u6oHVHgmwbAW HYk1oLueShqQrO5NwDIIIt3nQ0wPe+lXFvHLfJdcR44Vm1cmUOrbm8FRXIMphw5G8G9E nCYkW/MqVWSE/xcUHk7IFr8CNV8+E+yYJ1lrKdli5RbftR42zLJKrtplVLfzhP2ozTBD Qjsw==
MIME-Version 1.0
X-Received by 10.52.16.105 with SMTP id f9mr1083227vdd.28.1372232456022; Wed, 26 Jun 2013 00:40:56 -0700 (PDT)
In-Reply-To <dbeks81ca4e3nkbmfdmkie92m93dkd345d@4ax.com>
References <mailman.3757.1372103911.3114.python-list@python.org> <_JqdnQKrg4q12FTMnZ2dnUVZ_oydnZ2d@westnet.com.au> <dbeks81ca4e3nkbmfdmkie92m93dkd345d@4ax.com>
Date Wed, 26 Jun 2013 17:40:55 +1000
Subject Re: Is this PEP-able? fwhile
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3878.1372232458.3114.python-list@python.org> (permalink)
Lines 79
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1372232458 news.xs4all.nl 16011 [2001:888:2000:d::a6]:52687
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49232

Show key headers only | View raw


On Wed, Jun 26, 2013 at 10:47 AM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
> On Tue, 25 Jun 2013 17:20:43 +1000, Neil Hodgson <nhodgson@iinet.net.au>
> declaimed the following:
>
>>jimjhb@aol.com:
>>
>>> Syntax:
>>> fwhile X in ListY and conditionZ:
>>
>>    There is precedent in Algol 68:
>>
>>for i from 0 to n while safe(i) do .. od
>>
>         The REXX variant would be
>
> do for i = 0 to n while safe(i)
>         ...
> end
>
>         Basically one has an optional "for" clause ( for index = initial to end
> by step ), and one has an optional while/until clause -- Hmm, wonder if
> some interpreters would parse both while and until <G>. I need to install
> Regina Rexx on this new machine...

Modulo the 'for' keyword, which is superfluous there. Here's a test
script I knocked up on my OS/2 box back home:

/* */
do i=0 to 9 while safe(i)
        say i" is safe"
end
exit

safe: procedure
return arg(1)\=6

The \= in the last line is the REXX "not-equal" operator, like != in
Python. This outputs:

0 is safe
1 is safe
2 is safe
3 is safe
4 is safe
5 is safe

and then terminates. It's pretty clean; the DO/END construct defines a
block, and may optionally execute it more than once. With no
arguments, it just creates a block that executes once (equivalent to
C's braces); valid args include FOREVER (infinitely loop), WHILE
condition (iterate while condition is true), UNTIL condition (execute
once, then check condition, iterate while condition is false - like a
do/while in C), var=value (eg "I=1" - set var to value, then increment
by 1 or by the "BY" value, continue forever or until the "TO" value),
and possibly another that's slipped my mind. Aside from FOREVER, which
stands alone, they're completely independent.

But that's syntax, lots of it. What I'd like to see in Python is
simply a bit of flexibility in the rule about newlines. The for/if
construct in Python could be exactly the same as it now is, only with
the two statements on one line, and it would look very similar to the
existing notation. I can already one-line a simple statement:

for i in range(10): print(i)

I just can't put in an if:

>>> for i in range(10): if i%3: print(i)
SyntaxError: invalid syntax

But I can, as long as I use expression-if:

>>> for i in range(10): print(i) if i%3 else None

Seriously, I can use Perl-style notation to achieve this. Does that
seem right to you? *boggle*

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Is this PEP-able?   fwhile jimjhb@aol.com - 2013-06-24 15:52 -0400
  Re: Is this PEP-able?   fwhile Neil Hodgson <nhodgson@iinet.net.au> - 2013-06-25 17:20 +1000
    Re: Is this PEP-able?   fwhile Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-06-25 20:47 -0400
    Re: Is this PEP-able? fwhile Chris Angelico <rosuav@gmail.com> - 2013-06-26 17:40 +1000

csiph-web