-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature request: making "else" optional #1824
Comments
I just wrote a patch for this, and it seemed pretty easy. If this seems reasonable I'm glad to make a PR. The main thing is I'm noticing that my newer |
The thought has occurred to me before. My concern had been whether the Maybe tomorrow I'll have time for jq code reviews... |
I tried to consider that as an option too, but it didn't make a ton of sense when I compare to other languages. I think empty would be odd since in most languages an |
We already have |
@chancez - There has never been much doubt that if In my mind, therefore, the question has been whether to support
That is, if this (or a similar) def of |
Oh i see. While I think a
|
Further, it seems this doesn't quite make sense to me:
This sounds a lot more like the following condition expression: That said, I'm having a hard time thinking about this so I might be missing the issue. |
@chancez: Yes, you might be missing the issue. Consider expressions like these:
|
I definitely think I am missing something, but I'm not sure what your trying to illustrate. |
I'm trying out For example, between these 3, I think the else-less if conditional is the easiest to read: If else:
using
Using
|
@chancez wrote:
The crux of the matter is that some people might reasonably expect:
to emit 0, while others might reasonably expect it to emit nothing. (Perhaps you might try to consider what you would have expected had you not already implemented it.) Please note that I'm quite comfortable about jq supporting |
I see. Yeah, I can see what you mean now. I guess the way I see it is how other languages behave. Never have I see a failing if condition (without another branch like an It could certainly be argued if you "optimized away" the condition, you would be left with something like |
Note that |
Oh, I see. That's....interesting. |
Is that because it's neither true or false? |
It's because [1,2,3] | .[] | if . == 2
then
(if empty then "EMPTY" else . end)
else
.
end This outputs 1
3 |
Ah, empty is a way more nuanced and tricky than I understood it to be. Thanks. |
@pkoppstein I think |
@chancez Regarding |
@nicowilliams - It's odd that you think you might be missing something, because you yourself wrote:
In any case, it seems to me that the main argument against supporting
to be identical to: if empty // false then X else . end rather than to
(I've emphasized this potential confusion rather then the third possible interpretation because, as you said, the potential reading of |
@pkoppstein To me the form of the conditional has nothing to do with anything here. I have before worried that the default Maybe we should have a
But that doesn't help if you have |
@nicowilliams - It's genuinely puzzling to me that when I explicitly agree with you, you seem to see disagreement. By the way, now that the main obstacle to adding to builtin.jq has been removed, could you please consider #1260 -- it's been over two years since Erik made this important contribution. |
Yes, thanks for the reminder, we;ll restart integration of new builtins. We should, however, have a concept of builtin modules that one could import:
|
I think it would really help shorten expressions if the
else
clause inside anif
could be omitted, returning.
by default.For example the following two programs would be considered equivalent:
The text was updated successfully, but these errors were encountered: