-
Notifications
You must be signed in to change notification settings - Fork 699
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
Updated note on arrow notation #5854
Conversation
Visit the preview URL for this PR (updated for commit 4229368): |
src/content/language/functions.md
Outdated
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;). | ||
Expressions return values. | ||
This means that you can't write code in a place that expects a value. | ||
In the previous example, | ||
`_nobleGases[atomicNumber] != null;` returns a boolean value. | ||
The function then returns a value if the `atomicNumber` falls into | ||
the noble gas range. The function does nothing but return a value. |
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'd be careful with the term "return" as one might mistake it as "exit a function with a return value". Perhaps "evaluate" or "produce" might be a better term when referring to expressions?
Also, I think the distinction between an if statement and conditional expression is interesting. It shows an example of what you can't use with the arrow syntax.
Here's a potential alternative:
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;).
Expressions are anything that evaluate to a value.
For example, you could use a [conditional expression][] but not an [if statement][].
In the previous example,
`_nobleGases[atomicNumber] != null` is an expression that evaluates
to `true` if `_nobleGases` has an entry with the key `atomicNumber`.
src/content/language/functions.md
Outdated
the semicolon (;). For example, you can't put an [if statement][] | ||
there, but you can use a [conditional expression][]. | ||
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;). | ||
Expressions return values. |
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.
"return" -> "evaluate to" maybe?
src/content/language/functions.md
Outdated
there, but you can use a [conditional expression][]. | ||
Only _expressions_ can appear between the arrow (=\>) and the semicolon (;). | ||
Expressions return values. | ||
This means that you can't write code in a place that expects a value. |
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 wouldn't say "code". Expressions are code. Maybe keep the reference to statements? e.g. "...you can't put a statement (for example an [if statement][]) after the arrow."
src/content/language/functions.md
Outdated
This means that you can't write code in a place that expects a value. | ||
In the previous example, | ||
`_nobleGases[atomicNumber] != null;` returns a boolean value. | ||
The function then returns a value if the `atomicNumber` falls into |
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.
The function returns a value no matter what, it just returns true
or false
depending on atomicNumber
.
@leafpetersen , @loic-sharma : PTAL. |
you could use a [conditional expression][] but not an [if statement][]. | ||
In the previous example, | ||
`_nobleGases[atomicNumber] != null;` returns a boolean value. | ||
The function then returns a boolean value |
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.
The function always returns a boolean value. Maybe "The function then returns a boolean value indicating whether or not the atomicNumber
..."?
For example, | ||
you could use a [conditional expression][] but not an [if statement][]. | ||
In the previous example, | ||
`_nobleGases[atomicNumber] != null;` returns a boolean value. |
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 would take the ;
off of here. It's not part of the expression. _nobleGases[atomicNumber] != null
is the expression (which produces a value). The ;
is a terminator which separates the function declaration from the declaration which follows it.
Also, consider saying "produces a boolean value" or "evaluates to a boolean value" instead of returns, since return is usually associated with a function producing a value (which you capture in the next sentence).
Fixes #4582