-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
documentation of a significant jq/gojq inconsistency re $-variables in function definitions #107
Comments
I know this is a wired behavior of jq, and sometimes causes confusing behavior (jqlang/jq#2039), so fixed in gojq. |
@itchyny - I'm a bit confused by your comment. I was asking that the discrepancy (between gojq's non-weird behavior and jq's weird behavior) be documented as a difference, but as far as I can tell, you've closed the issue without updating the README. On the other hand, if by "fixed in gojq" you mean you intend to change gojq so that it mimics jq's (weird) behavior, I would have expected the closure of this issue to be linked, as you usually do, to the corresponding commit. Not that it much matters, but I'm fine with the discrepancy, and I'd be fine with gojq tracking jq on this particular discrepancy, but as with all important discrepancies, I'm hoping that it will be clearly documented. Not least because this particular discrepancy bit me (quite badly in that I lost quite a lot of time ...). Btw, I'm assuming that by "wired" you mean "weird" .... |
Sorry, I thought I've written in README before but was not written. And this behavior looks on the edge of jq bad parts and jq bugs. I'm totally knocked down by the weather right now, so judge later. |
When I implemented the compiler I thought this behavior is a jq bug, but since the issue is labeled as not a bug by nico, unlikely fixed in the future, and fixing in gojq simplifies the compiler a bit. I decided to fix this to match the behavior of jq, but it has some runtime cost (a value argument requires two local variables, also difficulty in optimizing constant arguments). |
@itchyny - On further reflection, it is apparent that the weird behavior of jq The evidence that it is really a bug is right there in the manual,
is short-hand for:
This was the intent all along (I participated in the discussions (So the only mystery that remains is why Nico added the "not-a-bug" tag. a) it won't be fixed in version 1.x; or b) the intention to achieve the equivalence of #1 and #2 is not a bug.) Whether it's called a bug or not, jq's current behavior is clearly My argument in favor of fixing the problem has several facets, but at |
jq handles "$-arguments" in function definitions as implicit "as" statements,
whereas gojq does not. This introduces a source of potential inconsistency.
Consider for example:
This works as expected in both jq and gojq.
However, if prodEq were defined as:
then we would see the discrepancy, as jq implicitly expands
the definition of prodEq to
Because of shadowing, in jq, prodEq would therefore always returns true!
For example:
The text was updated successfully, but these errors were encountered: