-
Notifications
You must be signed in to change notification settings - Fork 705
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
Statement vs expression in => fat arrow explanation #4582
Comments
I think the examples are fine. They are statements when used as statements.
Correct, Ditto for You're not saying this, but I'll address it anyway: That Whether a sequence of characters/tokens is a statement or not also depends on the context they're parsed in, because that decides what they're parsed as. The examples here are of code that are statments when they're used as statements, if you use them where a statement is expected and allowed. And if you use them anywhere else, one shouldn't be surprised that they're not statements in a place where statements cannot exist to begin with. Or stated differently, if If you plug the same sequence of characters into a different context, then it parses differently, and usually the
In the last three cases, the |
@lrhn Thank you for your thorough explanation! |
Page URL
https://dart.dev/language/functions
Page source
https://github.com/dart-lang/site-www/tree/main/src/language/functions.md
Describe the problem
The docs in the linked page state:
In describing what a statement is in this Stack Overflow answer, I listed some examples of statements, including the following:
myInt = 1;
print('hello');
return null;
if (name != null) { return name; } else { return 'Guest'; }
One reader commented:
That's true:
Am I wrong in my understanding of what a statement is? Is
i = 3
an expression rather than a statement? Isprint(i)
not a statement?Or is the documentation misleading?
Expected fix
If I'm wrong about what a statement is, then nothing needs to be changed about the documentation note above. However, we should define the terms statement and expression somewhere within the docs since these terms are used liberally without a clear explanation.
If
i = 3
andprint(i)
are in fact statements, then we should refine the => fat arrow note in the docs. I'm not exactly sure what that better wording would look like, though.Additional context
No response
The text was updated successfully, but these errors were encountered: