-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix scope related bug #53
Comments
@eddycharly that’s a good question and my interpretation of the spec (which I did not write) is that it should still be using the scope up for the entire duration of the So indeed:
So I do not think that is a bug. |
The non specified behaviour is actually triggered by this part of the spec:
Which implicitely can be interpreted as if a scope has a lifetime tighed to the entire duration of the |
My interpretation is that once the scope chain was used to lookup something, this something becomes the only thing available for further processing. With
From what I understand scope chain applies only until something is looked up from the chain. How can we clarify this point of the spec ? |
I'm definitely not comfortable with the current behaviour :( |
For clarity, my understanding of your interpretation is that the scope chain should apply:
Consider this compliance tests (which I did not write either): Given: {
"nested": {
"a": {
"b": {
"c": {
"fourth": "fourth"
},
"third": "third"
},
"second": "second"
},
"first": "first"
}
} The following expression:
Returns: {
"first": "first",
"second": "second",
"third": "third",
"fourth": "fourth"
} In the third nested level, the
Is your interpretation so that at this point, the scope chain should be considered as not available for the rest of the evaluation?
Returning: {
"first": null,
"second": "second",
"third": "third",
"fourth": "fourth"
} I think that’s a point worth clarifying indeed.
We need to discuss the JEP with the wider community – although there is not much traction at the moment. |
Kindly ping, @jamesls would you mind clarifying the expected behaviour here ? 🙏 🤞 |
@eddycharly for context: This bit in particular addresses your concerns. |
@springcomp thanks for the links ! Unfortunately I still find the current behaviour quite confusing. The way we stack scopes is pretty clear but the way we use the scopes to resolve fields is not. I wonder if it would make sense to use a function to enable lookup in scopes instead 🤔 |
In my understanding, the result of evaluating the expression:
would be: {
"first": null,
"second": null,
"third": null,
"fourth": "fourth"
} because |
This could be rewritten to: To get the expected behaviour though. |
While I agree the current behaviour with Specifically, I would expect the full original context and scope chain to be available when evaluating:
|
We could also use a function for that: In the expression above the |
I would favor a design where the For instance, I will try to illustrate what I think are entirely reasonable and actually quite intuitive expressions and their results – using the ✅ symbol – with contrast to what I think would be counter-intuitive – using the ❌ symbol – hereafter. Please, note that all the intuitive (to me) examples below are currently working as I would expect them to. multi-select-hash
multi-select-list
projections
Some more contrived examples:
⬆️✅
⬆️❌ In fact, this expression should be completely equivalent to:
⬆️✅ Which I expect would still work with your interpretation. Additionnaly, I think this would render the whole feature useless as you may want to create a nested scope from the outer scope. For instance, like so:
Whereas, I’m not sure in which way you would expect this expression to fail.
|
I think the main – if not only – source of confusion comes from the arguably counter-intuitive behaviour when evaluating the RHS of a Something like: case parsing.ASTSubexpression:
left, err := intr.Execute(node.Children[0], value)
if err != nil {
return nil, err
}
if left == nil {
return nil, nil
}
- return intr.Execute(node.Children[1], left)
+ return intr.WithScope(nil).Execute(node.Children[1], left) |
I'm definitely not sure what should be done. Right now, I'm considering adding a configuration option to let the user decide if he wants to support |
The solution might indeed not be as simple as I thought in my post above.
I would really like we work together towards improving / clarifying the spec. Library authors are indeed free to offer additional features but I think it would be best to prevent fragmentation. At the very worse, such a flag would need to be opt out rather than opt in which might not be satisfying to you. I agree it would be great to close the sub expression confusion. But let's focus on my examples above. |
A comment I made in the original proposal called out that it's not entirely clear what the expected behavior should be. In seems like there's a lot of interest in this feature, so I updated the original tracking issue with a new proposal that's essentially "just use the More details here, let me know what you think: jmespath/jmespath.site#6 (comment) |
Thanks @jamesls ! I asked a small question in jmespath/jmespath.site#6 directly. It looks close to what I had in mind #53 (comment) |
@eddycharly the more I study this, the more I’m convinced we are on the right track. Indeed, I am convinced that we need chained Additionally, I came to the realization that:
Therefore, may I kindly request that you please re-introduce JEP-11 into this repository? At the same time, I will obsolete JEP-11 in favor of my preferred JEP-11a option which, for reference is:
My goal is to write and publish JEP-11a as soon as I can to the best of my abilities. |
Strangely enough I'm convinced with the opposite. To me accessing something from a parent scope does not sound natural. It doesn't work this way in most programming languages, functions have a well defined signature and you never access variables declared in the caller implicitly.
I will add it back with an option to turn it off. As an end user I don't want to ship our product with support for such a confusing syntax.
It would be nice to get this discussed, if we want to go this way I think I prefer the introduction of a keyword based syntax just because it becomes possible to check bindings are valid at compile time. |
In the sake of hearing all arguments, can you please try and implement the scenario referred to above with your proposal?
An option to turn this feature off would be a good middle ground, thank you for that.
I’m very much in favor of discussing alternatives. I have actually started prototyping James’ proposal and I’m not particularly pleased with the result to be honest. If that is the consensus we land on, however, I will be more than happy to oblige and abandon JEP-11 for good. |
How does this finds |
I'm not sure we need lexical scope here though. Isn't the expression below correct ?
|
Hum, not quite. By the way, the expression I shared above works 100% if that’s your question 😁. I have actually tested it using both the Python implementation – using The .Net implementation is also surfaced on the JMESPath website’s preview page and you can try it there to convince yourselves. |
|
By the way, to be on equal footing when discussing with James, we cannot use the |
@springcomp with your solution:
first_name and last_name are not there. |
Using |
😯 I’m a bit embarrassed as I was focusing on the count.
Indeed |
@springcomp for completness here is an expression not using
|
Thank you very much. I now have a deeper understanding for your proposal. However, you are effectively creating the chain yourselves in your expression. But +1 for being stubborn and proving me wrong. 🙊 |
We don't need chained scopes, but it doesn't mean we don't want them ;) Relaxing on being explicit is less verbose and in this sense I like the @jamesls new proposal because while being less explicit and potentially weak, it is still easily verifyable. |
To compare with @jamesls new proposal:
If I make a typo, with this design it's easy to detect it at compile time:
It can look like a detail but from an end user perspective this makes a real difference, I can now warn users of my product that the expression they wrote is incorrect. |
But what I like about isolated scope is that it's extremely simple to know what is available in the current scope, you only need to look at the enclosing |
@springcomp are we generating the lexer/parser code using a tool ? or is this done by hand ? |
Yes this is simple top-down parser hand-coded I’m afraid. Let’s proceed discussing his proposal. |
Here is how I would do it. |
Thanks, will look into it tonight. |
This test should fail:
Once
&a
has been looked up from the scope, we should not use the scope again to lookup.b
.@springcomp am I right thinking we have a bug here ?
The text was updated successfully, but these errors were encountered: