Could you give an example of some real code that would be improved by this 
construct?

> On 21 Dec 2019, at 17:42, Soni L. <fakedme...@gmail.com> wrote:
> 
> I'd like to see the ability to do:
> 
> if x:
>   1
> and if y:
>   2
> or if z:
>   3
> 
> The truth table for these would be:
> 
> x | y | z | result
> 0 | _ | 0 | (none)
> 0 | _ | 1 | 3
> 1 | 0 | _ | 1,3
> 1 | 1 | _ | 1,2,3
> 
> and each statement is evaluated once, when encountered. (as such, y and z may 
> not be evaluated at all, if their evaluation is not necessary to determine 
> the outcome.)
> 
> This enables the usage of fallthrough - "or if" is a fallthrough case, and 
> the "or" in it is because its body gets evaluated either if the parent if's 
> body got evaluated, *or* if the orif expression is truthy.
> 
> "and if" is only suggested here for the sake of 
> analogy/consistency/something. we have "and" and "or" and it'd be kinda weird 
> to have "or if" without an "and if". it's equivalent to having a nested "if" 
> at the very end of the "if" body. (only runs if the parent body ran *and* the 
> expression is truthy.)
> 
> also, I'm sure some of you will argue that the truth table should look more 
> like this instead:
> 
> x | y | z | result
> 0 | _ | 0 | (none)
> 0 | _ | 1 | 3
> 1 | 0 | 0 | 1
> 1 | 0 | 1 | 1,3
> 1 | 1 | _ | 1,2,3
> 
> and I say, no it shouldn't. if it were to do this, you'd have a hard time 
> defining the semantics of elif and else for this. (just try it, it'll make 
> your head spin.)
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/5UKDW3NVGTM3E4TORZN42G6S4ZX42TZD/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/C5Q73RJXJWSLS3T5A6VD5HZ33Y72OFIT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to