-
Notifications
You must be signed in to change notification settings - Fork 306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds else if
and else
conditional clauses
#699
base: wdl-1.3
Are you sure you want to change the base?
Conversation
70ec19d
to
4cd725b
Compare
4cd725b
to
28286a9
Compare
I agree with this, though I'll admit my programming background bias. I find it more complicated to create two unconnected @geoffjentry said:
And I can point to at least one instance of this pattern in our |
@@ -7146,11 +7146,11 @@ Example output: | |||
|
|||
### Conditional Statement | |||
|
|||
A conditional statement consists of the `if` keyword, followed by a `Boolean` expression and a body of (potentially nested) statements. The conditional body is only evaluated if the conditional expression evaluates to `true`. | |||
A conditional statement consists of one or more conditional clauses. Each conditional clause is comprised of an expression that evaluates to a `Boolean` and an associated clause body. When a conditional statement is executed, each of the conditional clauses is evaluated sequentially: (a) the expression for that clause is evaluated and, if the returned value is `true`, the body of that clause is executed and the entire conditional statement suspends further execution. The simplest conditional statement contains a single "if" clause, which is the `if` keyword, followed by the clause's boolean expression, and, finally, the clause body of (potentially nested) statements wrapped in curly brackets. | |||
|
|||
After evaluation of the conditional has completed, each declaration or call output in the conditional body is exposed in the enclosing context as an optional declaration. In other words, for a declaration or call output `T <name>` within a conditional body, a declaration `T? <name>` is implicitly available outside of the conditional body. If the expression evaluated to `true`, and thus the body of the conditional was evaluated, then the value of each exposed declaration is the same as its original value inside the conditional body. If the expression evaluated to `false` and thus the body of the conditional was not evaluated, then the value of each exposed declaration is `None`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this paragraph probably needs to be expanded upon.
It should probably read that the declarations within the if
, else if
, or else
body that executes (depending on the evaluation of the conditional expressions) will be assigned to the values of their declarations; the declarations in the bodies that did not execute will be None
.
This change proposes extending conditional statements to include
else if
andelse
clauses.These types of clauses have been proposed many times on Slack and more formally in #268 and #697. Overall, the feedback seems positive, though concerns have been raised as to whether the cost of added complexity is worth it (see #697 for more details). I have made my case at the end of #697 that I feel it's actually removing mental burden/complexity to add these clauses into the language.
Closes #268.
Before submitting this PR, please make sure:
README.md
or other documentation to account for these changes (when appropriate).CHANGELOG.md
describing the change and linking back to your pull request.CONTRIBUTING.md
document.