|
LCS-2016-094 |
|
2 {25-Jan-2017} 1 {23-Dec-2016} |
|
25-Jan-2017 |
|
Voting |
|
Jim Lewis |
|
Main.JimLewis |
|
Conditional Return Statement |
|
Conditional Return Statement |
return_statement ::=
[ label : ] return [ expression ] [ when condition ] ;
return (a when c else b) when done;
-- Thomas Preusser - 2017-02-23
@KJ: The use case "return (<expression 1>) when <condition 1> else <expression 2>) when <condition 2> else..." could also be accomplished by:
return (<expression 1>) when <condition 1>; return (<expression 2>) when <condition 2>; ...And this is also much easier to read than putting it into one line. -- Martin Zabel - 2017-02-24 Martin, I'd say that's only true for complex cases. The real use model to me is simple cases, the ones where you don't tie yourself in linguisitic knots in the writing of them. I'd sure like to be able to say both.
return A when (SEL = '1') else B;
and
return '0' when not ANDTERM;
and not have strange syntactic differences between them, given that I don't have them when I use a conditional assignment. I just want a nice, clean, high symmetry language.
-- Rob Gaddi - 2017-02-27
To continue rambling on about what I was going on about on during the meeting on the 23rd...
Combined with 36a, my preferred evolution of this is:
return_statement ::= [ label : ] return [ conditional_expression_or_unaffected ] ;where a resultant value of
unaffected
means that you don't return, and instead continue with execution. Yes, you could use that
to go around writing horrible things with explicit use of unaffected rather than have unaffected only come through as the implicit catch-all else
clause. But people could do a lot of horrific things. What it really gives you is exactly what I said in my comment above; a unified syntax for anywhere you're using when
to create a conditional thingy, regardless of what type of thingy you want to do conditionally.
It would mean that:
return '1' when A else '0' when B;
return ('1' when A else '0') when B;
when
be a part of an entirely separate language chunk, then 1) has to be written return ('1' when A else '0') when (A or B);
which buries the intent.
-- Rob Gaddi - 2017-02-27
@Rob: See LCS094a for a proposal that provides what you want.
-- Thomas Preusser - 2017-02-27