-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add new proposal for lexical scoping #18
Conversation
See jmespath/jmespath.jep#18 for more details.
FWIW I took a shot at implementing this in python, and it turned out to be pretty straightforward in case anyone wants to experiment with let expressions: jmespath/jmespath.py#307 . I'm taking it as a good sign that the implementation was really straightforward and fairly minimal. |
@jamesls thanks tons for the timely feedback and progress. This is really appreciated. The JEP is really complete. The only thing I would suggest needing calling out for is how to access potential properties called I think, within a Are Given: { "let": "in" } Which of the following expressions are legal, if any?
I think the last expression is definitely valid. What about the first? For instance:
|
May I kindly suggest we call this JEP-11a? |
All of those are legal. There's nothing in the proposed grammar changes that would result in a parse error. Using
Yes, new additions must be backwards compatible. These are valid identifiers with the current specification, they will continue to be valid. This will need to hold true for any keywords that get added in future JEPs. I can update the JEP later with word clarification on these keywords as well as additional testcases. |
See jmespath/jmespath.jep#18 for more details.
Of course. I naïvely started to tokenize
Yes, indeed, I think that is definitely worth mentioning. |
@jamesls what about making the This would effectively set the last part of the Maybe:
|
What would be the motivation for doing this? Is there a specific issue/usability problem it's trying to address? |
There are no immediate issue or usability problems. I have been thinking about a potential future Something that may look like (provided there were support for simple arithmetic operations):
In a reduce operation, the issue is to be able to both name and assign a value to the accumulator. A potential proposal I had in line with JEP-11 was to use a "scope" object as the first argument:
That way, |
Got it. I think it'd be better to explore that in a separate proposal, as one of the key things in a JEP is having sufficient motivation as to why something's added. I briefly mentioned it in this JEP, and I believe elsewhere in one of the other So I'd research either adding rust/ruby style closures or javascript arrow functions to the spec, and see 1) is it even possible and 2) if the additional complexity is worth the use cases it enables. But at any rate, worth a separate discussion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, James! It addresses any concerns I had around JEP 11. The addition of $
makes the difference between variable access and current node access explicit. The introduction of a contextual keyword for let
is great and makes this much more readable than a function.
proposals/0000-lexical-scope.md
Outdated
subsequent references using the `variable-ref` MUST NOT continue projecting | ||
to child expressions. For example: | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that these are meant to be considered separately is a little hard to sus out. Maybe separate code blocks or at least add a newline between them.
proposals/0000-lexical-scope.md
Outdated
This JEP does not require that implementation provide this capability of | ||
passing in an initial scope, but by requiring that undefined variable | ||
references are runtime errors it enables implementations to provide this | ||
capability. Implementations are also free to provide an opt-in "strict" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, makes sense. I'd probably add some kind of predefined-params option to the linters in https://github.com/awslabs/smithy/tree/main/smithy-jmespath/src/main/java/software/amazon/smithy/jmespath.
See jmespath/jmespath.jep#18 for more details.
It looks like expressions like To me, it looks like if variables are set up in the same order they are declared it would make sense to allow that. Allowing this could be useful and help simplifying expressions. Now |
This is allowed and is a valid expression. It means that
I mentioned in the rationale that I want to stick to existing precedent here unless there's a good reason to deviate. Give an expression Rather, your suggestion is somewhere in between where given N binding clauses, the evaluation of binding
A few extra characters while sticking to established precedent seems like the right tradeoff for me. |
I'm not a functional programming language expert at all and that's probably why i find it counter intuitive. Most (if not all) languages allow referencing previously declared local variables: func f() {
var a = 10
var b = a // `b` depends on `a`
// ...
} Anyway, I'm fine with both. |
Right, and I want to be clear that I think that's a reasonable thing you might want to do. My previous comment was saying that it's possible to do that with this proposal in a way that adheres to existing precedent and has syntax almost identical to what you've quoted:
Swap out |
Ok, looks like there's no more comments to address and we've had a couple weeks for feedback. At this point, I'm going to go head and accept this JEP. Thanks to everyone that helped with the ideas behind this JEP over the years, excited to add this to the language! |
See jmespath/jmespath.jep#18 for more details.
This is a new proposal for lexical scoping based on comments here.
This supersedes JEP-11.