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

syntax: explain that rust pervasively allows separators to be used as terminators #2071

Open
fw-immunant opened this issue May 9, 2024 · 0 comments
Assignees

Comments

@fw-immunant
Copy link
Collaborator

I don't think we have it anywhere in our speaker notes, but we should make an explicit mention of it. Usually when teaching I try to bring this up around when semicolons are discussed or when we talk about tuple and array types.

This is a nice feature of the language that's easy to miss if not called out: to minimize git diffs, almost every syntactic construct in Rust allows separators to also be used as terminators. This includes commas in tuple and array values, semicolons separating expressions (though the trailing semicolon does have semantic meaning in this case), and even pipes as leading delimiters in patterns (as in Standard ML or OCaml):

match 'x' {
	| 'a' => 1,
	| 'b'
	| 'c' => 2,
	| _ => 3,
}
@fw-immunant fw-immunant self-assigned this May 9, 2024
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

No branches or pull requests

1 participant