-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Python list initializers & equal initializer syntax #544
Conversation
Thanks for taking the time to simplify the Python generator. I like the simplified logic of the generator itself. However, I have the following concerns:
Finally, I suggest that the following two tasks must also be dealt with:
|
Thanks for your review! I'll get busy with the tasks you outlined. I don't find The I would be fine with your proposition (i), but IMO a more satisfactory candidate would be to stop using parentheses to denote assignment, which to me is the unintuitive thing here. If we replace them with an
The general grammar is just If that is not an option, then I'd prefer your proposal (i) or my proposal. |
I agree with @oowekyala that our current syntax can be described as @oowekyala might be right about our |
I also agree with @oowekyala that our current assignment syntax could use a bit of a boost. I think the end result of having
How so? I think Swift, Scala, and Rust seem to be using this After reading your comments and trying out a few examples and patterns in Python, I am convinced that |
I guess it's just me then :). This syntax would definitely be more natural for Rust and Python programmers |
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 looks good to me. Please be sure to update the wiki pages for the affected target languages so that this new syntax is documented.
@oowekyala Is this ready to merge? |
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 looks really good!
Should we open an issue for the assignment operator discussion? I think it's important to keep track of it.
Please don't forget to update the wiki and the example and the benchmark before merging in. |
I've just updated the wiki. I reorganised the language specification page a bit (added an appendix about types and one about expressions, to clean up the section about parameter declarations, which had the burden of explaining everything since it's the first section on the page). Feel free to change things. I just realised i forgot to update the python page though... |
Ok I think I'm done with the wiki, and AFAICS no more code needs to be updated I'll merge this shortly and open the issue @cmnrd referred to |
Thank you for updating the wiki. There is a sentence in the Python entry that is left unfinished:
|
thanks for spotting this, it's fixed now! |
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
============================================
+ Coverage 66.43% 66.50% +0.07%
- Complexity 3466 3487 +21
============================================
Files 132 133 +1
Lines 22294 22325 +31
Branches 2876 2873 -3
============================================
+ Hits 14810 14847 +37
+ Misses 6345 6332 -13
- Partials 1139 1146 +7
Continue to review full report at Codecov.
|
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.
I'm a little confused about parameter assignments like foo = ([1, 2])
.
I agree with this, but this reasoning should not extend to parameter assignments which use a |
This was always a problem in the parameter syntax. You could always add useless parentheses. I think it's counter intuitive that So I'm fine with having duplicate syntax in parameter assignment, especially if we're phasing out using parentheses for assignment anyway. Also, parenthesized expressions could become a useful expression form if at some point we introduce syntax for infix operators. But, we should possibly make sure that |
After some discussion with @Soroosh129, I'm convinced that this (and the current implementation of lists in LF) needs more discussion. I think it's better to hold off from merging this into master; I propose to table this until after the tutorial. |
…th ported classes (changed in old Xtend code incorporated)
This reverts commit 5dd07de.
Things that are diverging from the spec (#986)
|
Now that you're back in action, @oowekyala, should we try to revive this effort? I feel like there were a lot of good contributions in this PR. @cmnrd addressed some of them, I believe, but there's still work in this branch that hasn't made it to |
Right. I already briefly spoke with @oowekyala about this. I also still have it on my TODO List to create an issue detailing several action items on the way forward. I'll try to take care of this soon. |
Note that I silently moved this to release |
Implement list literals for Python (see discussion #492, issue #507). Now:
(1, 2, 3)
as an initializer creates a tuple (previously created a list)([1, 2, 3])
as an initializer creates a listThis makes LF syntax in line with python syntax itself and allows writing
([])
([1])
Previously these scenarios required fat braces, eg
{=[]=}
.Using list literals in other targets than Python produces a validator error. When this is merged I'll follow up with the necessary changes for Rust to support this. TS could also support it.
The python code generator is simplified as there is no more special treatment for lists in parameters. Previously, initializing a parameter with
(1, 2)
created a tuple, while the same initializer for a state variable creates a list. I argue that this was hard to learn and not ergonomic, becauseyou can easily abstract it by turning it into
and the code means the same, regardless of what "
...
" is. Previously, this was not true for python if...
is a comma separated list, because the refactoring effectively makes the state variable be initialized to an immutable tuple instead of a mutable list, which may cause unexpected errors at runtime.I understand that this was supposed to honor the principle that parameters should be immutable, whereas state variables are not. However I think as shown above, this corner case has potent downsides, and doesn't buy us safety anyway: you could always initialize your parameter to a mutable thing, eg
{=[1,2]=}
, put mutable objects inside the tuple fields, or even set the parameter variable itself (I think), as Python doesn't support final bindings.Last things to do
array = { 1,2 }
in C/C++=
syntax in constructor calls