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

Seemingly contrary statements in 3.3 #2980

Open
2 tasks done
dennismarwood opened this issue Jan 1, 2022 · 2 comments · May be fixed by #3870
Open
2 tasks done

Seemingly contrary statements in 3.3 #2980

dennismarwood opened this issue Jan 1, 2022 · 2 comments · May be fixed by #3870
Milestone

Comments

@dennismarwood
Copy link

dennismarwood commented Jan 1, 2022

  • I have checked the latest main branch to see if this has already been fixed
  • 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/ch03-03-how-functions-work.html#function-bodies-contain-statements-and-expressions

Description of the problem:
Some clarification could be added to help differentiate the definition of functions, function bodies, function declaration, and function definitions.

The 3.3 section is describing statements vs expressions.
A description of statements says "Statements are instructions that perform some action and do not return a value."
Then below says "Statements do not return values."

But, in an apparent contradiction, it also says "Function definitions are also statements; the entire preceding example is a statement in itself." followed later by "Functions can return values to the code that calls them."

Suggested fix:
A line defining the relationship of function bodies, function declarations, and function definitions. Perhaps the removal of one of the terms if they are interchangeable. (I noticed that the description for listing 3-1 describes a "declaration" and then is followed immediately with a sentence about "definitions".)

A graphical description of all the statements and expressions and their relationships (statements can be made of expressions etc).

Statement
            |.........................|
                      |........|
fn main() { let y = { let x = 3; x+1 }; }
                            |.| |..|
                    |................|
|.......................................|
Expression
@carols10cents
Copy link
Member

Function definitions are statements; you can't say let x = fn main() {};. Function calls are expressions. Hope that clears it up for you right now; I'll think about how to clarify this in the text.

@carols10cents carols10cents added this to the ch3 milestone Jan 2, 2022
@dennismarwood
Copy link
Author

dennismarwood commented Jan 2, 2022

Thank you carols10cents that does it. A voice in the back of my head said that it was something to do with defining vs calling.

I think that the function definitions not ending in a semicolon was throwing me a off bit as well. And if you look at a call to a function it is immediately followed by a semicolon, though that semicolon is the ending of a statement somewhere. Or at least that is what I believe is happening :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants