-
Notifications
You must be signed in to change notification settings - Fork 120
TM009 if
Our current case construct that mirrors cond in Racket is unfamiliar and verbose. We should switch to a semantically similar, but more immediately understandable, if construct.
The proposed grammar is:
if expr:
block
else if expr:
block
...
[else:
block]
end
That is, an initial if clause, followed by any number of optional else if clauses, followed by an optional else clause.
It evaluates each branch if the condition evaluates to true. Non-true values don't cause the branch to be taken; this matches the existing semantics of case.
If an if expression doesn't match one of its cases, it ends in an error, just like case currently does. The message will say `"if: no cases matched".
For single-case, side-effecting computation, when should be used instead of if. The well-formedness checker should complain and recommend when if a single-case if is written (since either its condition is tautological, or it will throw an error in some cases).