-
Notifications
You must be signed in to change notification settings - Fork 299
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
language: add else clause as part of if comprehension #2122
Comments
Would this also imply the need for
I wonder about code like below, where someone is not aware of defaults and uses branching conditionals (
|
Now we have more data and know of several designs, in addition to considering future language extensions, I'm much more leaning to not supporting an Also, for now you can simulate a switch statement as such:
This avoids the problem, even now, of having to negate the The benefit of this
This is unnecessarily verbose. With the query extension, we foresee being able to instead write something like
The switch approach naturally allows for "else" values even in this case. A dedicated As said, you can use this "switch" idiom even in today's CUE. But we plan to have a bit more syntactic support for this, for instance:
This better signals intend and will allow I would also not be opposed to having a more dedicated language construct that handles this, although I'm not sure how this would look like if one wants to cover all cases. Maybe something like, using the more precise builtins
|
I like where this is going, though needing to supply an array to the penultimate More potential prior art to consider: Common Lisp's |
Personally I hope there is a Manually negating the if condition like the following snippet does is error prone. if a || b == 0 {
c: "category a"
}
if !a && b != 0 {
c: "category b"
}
... I'm not sure if this kind of usage can be covered by a switch construct. And I'm a little worried about the performance implication without a |
Is your feature request related to a problem? Please describe.
One of the more frequently asked questions on Slack and GitHub discussions is why
else
is missing from CUE (an incomplete list):See also #571, regarding
not()
builtin.In #111 (comment), @mpvl does not rule out adding else, saying:
Raising this issue to capture more data, experience, feedback etc, because right now there is not an open issue to capture such responses.
Describe the solution you'd like
Adding support for
else
clauses inif
comprehensions.Describe alternatives you've considered
Per #2092, explicitly stating the negation of the
if
clause, which leads to errors.Additional context
n/a
The text was updated successfully, but these errors were encountered: