book
book copied to clipboard
ch13-01 Description of closure syntax has been removed
- [x ] I have checked the latest
mainbranch to see if this has already been fixed - [x ] I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem: https://doc.rust-lang.org/book/ch13-01-closures.html
Description of the problem: The latest version of chapter 13 has removed the description of the basic syntax of closures.
Suggested fix: Insert the description of closure syntax from the previous version of chapter 13.
Yes, I'm making some edits to the closures section. Can you perhaps copy/paste the exact text of what's no longer covered from the old version of the closures section here: https://doc.rust-lang.org/1.60.0/book/ch13-01-closures.html (note the 1.60.0 version in the URL)?
Specifically, closure syntax is described in this current section: https://doc.rust-lang.org/book/ch13-01-closures.html#closure-type-inference-and-annotation right? What's missing, exactly?
Hi.
Thanks for replying. I'm thinking that the two or three paragraphs after Listing 13-5 in the older section describe the syntax in more detail for those who are just learning about closures. Just my two cents. I suppose that most people who are learning should be able to understand closure syntax from the vertical comparison with functions shown in the newer section.
The book is really great. Keep up the good work!
-Dan
The closure definition comes after the = to assign it to the variable expensive_closure. To define a closure, we start with a pair of vertical pipes (|), inside which we specify the parameters to the closure; this syntax was chosen because of its similarity to closure definitions in Smalltalk and Ruby. This closure has one parameter named num: if we had more than one parameter, we would separate them with commas, like |param1, param2|.
After the parameters, we place curly brackets that hold the body of the closure—these are optional if the closure body is a single expression. The end of the closure, after the curly brackets, needs a semicolon to complete the let statement. The value returned from the last line in the closure body (num) will be the value returned from the closure when it’s called, because that line doesn’t end in a semicolon; just as in function bodies.
Note that this let statement means expensive_closure contains the definition of an anonymous function, not the resulting value of calling the anonymous function. Recall that we’re using a closure because we want to define the code to call at one point, store that code, and call it at a later point; the code we want to call is now stored in expensive_closure.
On Mon, Jul 4, 2022 at 4:56 PM Carol (Nichols || Goulding) < @.***> wrote:
Yes, I'm making some edits to the closures section. Can you perhaps copy/paste the exact text of what's no longer covered from the old version of the closures section here: https://doc.rust-lang.org/1.60.0/book/ch13-01-closures.html (note the 1.60.0 version in the URL)?
Specifically, closure syntax is described in this current section: https://doc.rust-lang.org/book/ch13-01-closures.html#closure-type-inference-and-annotation right? What's missing, exactly?
— Reply to this email directly, view it on GitHub https://github.com/rust-lang/book/issues/3253#issuecomment-1174464470, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATLS5PHKTKRNXKPLN6CKNZLVSN2Y7ANCNFSM52PVCZ6A . You are receiving this because you authored the thread.Message ID: @.***>