Skip to content
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

Open
wants to merge 1 commit into
base: wdl-1.3
Choose a base branch
from

Conversation

claymcleod
Copy link
Collaborator

@claymcleod claymcleod commented Jan 26, 2025

This change proposes extending conditional statements to include else if and else 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:

  • You have added a few sentences describing the PR here.
  • You have added yourself or the appropriate individual as the assignee.
  • You have updated the README.md or other documentation to account for these changes (when appropriate).
  • You have updated the CHANGELOG.md describing the change and linking back to your pull request.
  • You have read and agree to the CONTRIBUTING.md document.
  • You have added or updated relevant example WDL tests to the specification.
    • See the guide for more details.

@claymcleod claymcleod self-assigned this Jan 26, 2025
@claymcleod claymcleod changed the base branch from wdl-1.2 to wdl-1.3 January 26, 2025 14:47
@claymcleod claymcleod added the spec change A suggested change to the WDL specification. label Jan 26, 2025
@claymcleod claymcleod force-pushed the feat/else-if branch 2 times, most recently from 70ec19d to 4cd725b Compare January 26, 2025 15:00
@a-frantz
Copy link

I feel it's actually removing mental burden/complexity to add these clauses into the language.

I agree with this, though I'll admit my programming background bias. I find it more complicated to create two unconnected if clauses with negated expressions than it would be to simply have an else (or else if) clause.

@geoffjentry said:

A question I'd have is: if one were to survey the world's breadth of public WDLs, how often do you see the above?

And I can point to at least one instance of this pattern in our workflows repository - https://github.com/stjudecloud/workflows/blob/main/workflows/qc/quality-check-standard.wdl#L351-L386

@@ -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`.
Copy link
Contributor

@peterhuene peterhuene Jan 28, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec change A suggested change to the WDL specification.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants