Conditional expressions (again)

Michael Abbott michael at rcp.co.uk
Thu Oct 25 11:55:51 EDT 2001


gbreed at cix.compulink.co.uk wrote in news:9r96tv$m26$1 at thorium.cix.co.uk:

> In article <Xns914595097EDBmichaelrcpcouk at 194.238.50.13>, 
> michael at rcp.co.uk (Michael Abbott) wrote:
>
>> Well, I don't really think there's a great deal of argument about the 
>> syntax.  There are, as far as I'm aware, two live proposals for syntax:
>> 
>> (1)           x = if a: b elif c: d else: e 
>>or
>> (2)           x = if a then b elif c then d else e 
> 
> I don't remember "elif" being generally supported.  

It's true that noneone talked much about elif; I guess I'm making 
assumptions.  However, once you've started there's no point at all in not 
supporting it.

 
> Or a good argument against
>                 x = b if a else (d if c else e)
> 
> unless you count "P*rl has something like that" as a good 
> counter-argument.

True, true.  Personally, I hate it (as the most confusing option), but 
you're right, we should remember it as a third option (poo).


> 
>> I seem to recall that Guido stated that he'd had a go at implementing 
>> syntax 2 (which I prefer if we're willing to pay the price of a new 
>> keyword 'then'), and that it worked well enough with the Python syntax. 
> 
> No "elif", and has to be parenthesised if it's used as a statement.

Hmm.  Well, that Guido may have forgotten to put in elif I'm sure was just 
a passing omission.

That we need to put parentheses around
    	(if a then b else c)
as a statement by itself is strange at first sight (and my first reaction 
was "nonsense!" :), but thinking about it -- does it matter?

Ok, we need the parentheses so that the parser knows that we aren't parsing 
an if statement, and certainly this is very surprising at first (as I say, 
my first reaction was to think that you were bringing up all that nonsense 
about requiring brackets around all if expressions).

However, does this matter?  It's a baby bleb, perhaps, but it's not going 
to hurt anyone, particulary as if expressions as statements are rather 
redundant!

> 
> 
>> The main argument, really, seems to be about whether this is useful.  
> 
> Yes, there's that one as well.

Ho hum, I expect it'll be the killer.



More information about the Python-list mailing list