AdaCore / ada-spark-rfcs

Platform to submit RFCs for the Ada & SPARK languages
63 stars 28 forks source link

Conditional statements #59

Closed jquorning closed 3 years ago

jquorning commented 4 years ago

Proposal

Statements are changed to allow conditional execution thereof based on the value of a boolean expression. The when keyword should be used to indicate a conditional statement.

Examples

Stop (Car, Emergency) when PB_EMCY;
--  Emergency stop Car when the pushbutton PB_EMCY is pressed.

Compile when Change or Force_Compile;

LED_05 := Set   when PB_Start;
LED_05 := Clear when PB_Stop;
--  SR Flip-Flop.

Rationale

It would be nice to be able to execute a statement depending on when a boolean expression evaluates to True. In many cases the program text would be shorter and arguably easier to read.

Implementation

It should be easy to implement in the compiler.

Alternative

when PB_Start then LED_05 := True;
when PB_Stop  then LED_05 := False;
--  SR Flip-Flop with focus on inputs.
--  The SR-FF in exmples has focus on output.
raph-amiard commented 4 years ago

Hi @jquorning.

While I appreciate that you wrote a code sample that allows one to infer what feature you would like, I must say this is still not enough for what we expect of an issue here:

In the future, we would appreciate if you give some thought to your proposal by writing something with a minimum of polish before posting it here :slightly_smiling_face: Thanks in advance.

jquorning commented 4 years ago

@raph-amiard , Thank You for your feedback. I home my latest changes bring more clarity to the proposed issue :-)

senier commented 4 years ago

In the future, we would appreciate if you give some thought to your proposal by writing something with a minimum of polish before posting it here slightly_smiling_face Thanks in advance.

@raph-amiard Maybe you should consider using issue templates to suggest a structure for new issues?

raph-amiard commented 4 years ago

@senier that's a great point, especially considering we have a template for RFCs, but not for issues! Thanks for the suggestion, we'll consider this.

raph-amiard commented 3 years ago

Hello @jquorning. We have considered this (also in the scope of a more constrained RFC, #31) and think this is too general and error prone. Closing this. FWIW on the other hand we are considering #31.

Kind regards

raph-amiard commented 3 years ago

@senier You'll be glad to know that we have issue templates now :wink: