Skip to content
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

RFC: Allow trailing comma after the last element of a list #2635

Closed
lenianiva opened this issue Oct 7, 2023 · 6 comments
Closed

RFC: Allow trailing comma after the last element of a list #2635

lenianiva opened this issue Oct 7, 2023 · 6 comments
Labels
RFC Request for comments

Comments

@lenianiva
Copy link
Contributor

lenianiva commented Oct 7, 2023

Proposal

Currently this is not legal Lean:

let li = [
  item1,
  item2,
]

but if it were legal, adding new elements would not entail changes to existing lines:

let li = [
  item1,
  item2,
  item3,
  item4,
]

This has two main benefits:

  1. Machine based code generation is simpler
  2. The diff generated by version control is easier to read when new elements are added. This is especially relevant to unit testing.

Trailing comma is already supported in Rust and Python.

Community Feedback

Ideas should be discussed on the Lean Zulip prior to submitting a proposal. Summarize all prior discussions and link them here.

Discussion thread

James Gllicchio proposed that we could also have preceding commas:

let li = [
  , item1
  , item2
]

Impact

Add 👍 to issues you consider important. If others benefit from the changes in this proposal being added, please ask them to add 👍 to it.

@lenianiva lenianiva added the RFC Request for comments label Oct 7, 2023
@lenianiva lenianiva changed the title RFC: Allow trailing comma in the last element of a list RFC: Allow trailing comma after the last element of a list Oct 7, 2023
@leodemoura
Copy link
Member

@Kha I think this is a good change, and I recall discussing it with you in the past. However, I don't remember why we didn't move forward. I don't have time to do it myself, but I will support a PR. BTW, let's ensure the trailing comma is accepted in other similar notation.

@lenianiva
Copy link
Contributor Author

@Kha I think this is a good change, and I recall discussing it with you in the past. However, I don't remember why we didn't move forward. I don't have time to do it myself, but I will support a PR. BTW, let's ensure the trailing comma is accepted in other similar notation.

What do you mean by accepted in other similar notation?

@kim-em
Copy link
Collaborator

kim-em commented Oct 9, 2023

e.g. if this is allowed, then rw [x, y, ] should be allowed as well.

@Kha
Copy link
Member

Kha commented Oct 9, 2023

However, I don't remember why we didn't move forward.

I am quite sure it was lack of sufficient motivation. So I agree with

I don't have time to do it myself, but I will support a PR.

@lenianiva
Copy link
Contributor Author

@Kha I think this is a good change, and I recall discussing it with you in the past. However, I don't remember why we didn't move forward. I don't have time to do it myself, but I will support a PR. BTW, let's ensure the trailing comma is accepted in other similar notation.

I have a PR here #2643.

@leodemoura
Copy link
Member

Closing this issue since PR #2643 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for comments
Projects
None yet
Development

No branches or pull requests

4 participants