[Patches] [ python-Patches-471421 ] conditional expression (if-then-else)
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 15 Oct 2001 12:47:25 -0700
Patches item #471421, was opened at 2001-10-15 11:59
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=471421&group_id=5470
Category: Core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Guido van Rossum (gvanrossum)
Summary: conditional expression (if-then-else)
Initial Comment:
Here's an implementation of conditional expressions of
the form
if <test> then <test> else <test>
It's hairier than expected because I'm trying to
require you to put parentheses around it in some cases
but not in others.
This still lacking:
- a PEP to motivate and explain it
- documentation
- tests
- needed changes to Modules/parsermodule.c
After applying this patch, you must regenerate the
grammar; the Unix Makefile and the current CVS version
of the Windows project file do this automatically.
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-10-15 12:47
Message:
Logged In: YES
user_id=6380
The 'fi' would disambiguate binary operators following the
else part. But I find it very unpythonic: we don't have
Algol-68 style reversed closing keywords anywhere else, and
when you squint you don't see the structure.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-15 12:44
Message:
Logged In: YES
user_id=31435
Martin, I don't think so. "The problem" is ensuring the
parser can distinguish a conditional expression from an if
statement, as they both begin with "if". A left paren
rules out an if-statement. If the conditional expression
*began* with "fi", no problem <wink>.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2001-10-15 12:34
Message:
Logged In: YES
user_id=21627
Would the grammar become simpler if the syntax was
if <test> then <test> else <test> fi
?
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-10-15 12:22
Message:
Logged In: YES
user_id=31435
FYI, the grammar is not regenerated by magic on Windows. I
very recently checked in Parser/grammar.mak (a Windows
nmake file), which you can use "by hand" (read the comments
at the top of the file) to regenerate the grammar if you
know that's needed.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=471421&group_id=5470