-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Rewrite and expand the closure section #594
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
Conversation
mdinger
commented
Jun 11, 2015
|
(rust_highfive has picked a reviewer for you, use r? to override) |
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.
supposedly?
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.
To someone unfamiliar with closures and particularly Rust's closures, they may not appear anonymous to the reader. All they have to go on is the fact that closures are also called anonymous functions. They don't have any evidence to support that fact themselves yet:
// Assign closure to `x`. It has a name `x` now. Anonymity implies no name but
// it has name `x` now.
let x = || 1; My intent was to point out the normal name and then to try to fill in the info so that the reader doesn't just have to trust that they're anonymous. He understands why it is.
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.
In a broad sense, 'anonymous functions' and 'closures' are two different things. Rust supports named and anonymous functions, and anonymous closures, but not named closures.
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.
(that said, i see what you're getting at here)
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.
Do you have examples to distinguish the 3? I interpreted the anonymity of a closure mainly in terms of the implicitly generated type it holds anonymously. That may or may not be correct but it's how I interpreted it.
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.
That may or may not be correct
Yeah, that's not what the anonymous part usually means.
Actually, come to think of it, Rust does not have anonymous functions currently, IIRC they're still closures with an empty environment.
JavaScript, for example, has anonymous closures:
counter = 0;
function () { return counter += 1; }
which you can assign to a var or just invoke immediately.
and named closures:
counter = 0;
function incr() { return counter +=1; }
you'd invoke this with incr(), because it has a name.
In Rust, you cannot give a name to a closure, ie, fn items are always functions, and don't close over their environment.
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.
Ah, I see what you mean by anonymous function though (which I wasn't sure about when you wrote that). I can tweak the wording then. Still, bringing the concepts of functions and closures together though makes Rust feel very cohesive.
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.
Oh yeah, for sure :)
|
Looks great t ome! |
|
Excellent! I'll try to go over it again in a day or so again before submitting for final review. |
|
r? @steveklabnik I added a couple tweaks to wording and some more links. I didn't rebase but it passed |
Rewrite and expand the closure section
|
Thanks! :) |