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

trailing comma in arrays #123

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

akihiro17
Copy link
Contributor

I would like Amber to accept trailing commas in arrays, but I'm not sure if that is a good choice for Amber.

script

let array = [
    1,
    2,
    3,
]

loop a in array {
    echo a
}

output

1
2
3

script

let array = [,]

loop a in array {
    echo a
}

output

 ERROR 
Expected expression
at test.ab:1:14


1| let array = [,]
2| 

script

let array = [1,2,3,,]

loop a in array {
    echo a
}

output

 ERROR 
Expected expression
at test.ab:1:20


1| let array = [1,2,3,,]
2| 

script

let array = []

loop a in array {
    echo a
}

output

 ERROR 
Expected array type or value before ']'
at test.ab:1:14


Eg. insert 'Num' for empty array or '1, 2, 3' for array with values

1| let array = []
2| 

@Ph0enixKM
Copy link
Member

Can you share your motivation behind this?

@akihiro17
Copy link
Contributor Author

I think this makes it a little easier to re-order elements in arrays.

Currently, Amber doesn't accept the script below. Therefore, to comment out the last element of an array, it is also necessary to remove the trailing space of the second-to-last element.

let array = [
    1,
    2,
    3,
    // 4,
]

loop a in array {
    echo a
}

And next time, when I want to remove the commented-out code, I need to reinsert the trailing space of the second-to-last element.

@b1ek
Copy link
Member

b1ek commented May 29, 2024

Can you share your motivation behind this?

some people just like their arrays with a trailing comma. i do it sometimes too, when i want only one line to show up in git diff, not two

Copy link
Member

@b1ek b1ek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thanks for your feedback. LGTM

@Ph0enixKM Ph0enixKM merged commit 225d8c4 into amber-lang:master May 29, 2024
1 check passed
@akihiro17 akihiro17 deleted the trailing-comma branch May 29, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants