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

Link to explanations of r-value, l-value and lint #152

Merged
merged 2 commits into from
Jul 3, 2014

Conversation

vks
Copy link
Contributor

@vks vks commented Jul 2, 2014

I think those terms are not common knowledge for a lot of readers, so I linked the corresponding Wikipedia articles. We might even want to consider explaining them in Rust by Example.

@japaric
Copy link
Member

japaric commented Jul 2, 2014

@mdinger

Do these wikipedia links look "good enough" to you? Or are they too general/abstract?

Also, could you edit the first comment of issue #97 so that it renders as a TODO list (like issue #1)


We might even want to consider explaining them in Rust by Example.

We could add a (single page) glossary to the book, in the same spirit of the rusticon, for terms that may be unfamiliar; and then link these terms to it (using anchors). Opinions on this?

@vks
Copy link
Contributor Author

vks commented Jul 2, 2014

I think the links are better than nothing (they give background on where those words come from). This pull request addresses the in my opinion worst offenders from issue #97.

A better solution would be a glossary that includes one-sentence definitions and the links.

@mdinger
Copy link
Contributor

mdinger commented Jul 2, 2014

I think both links are definitely better than nothing. Neither is really bad. The text for r-value/l-value is heavy and abstract but you can understand it if you think about it. It doesn't have lots of unknown words which raise the difficulty. I would add them at least until there is a glossary or something to help out.

I tried to form their example text into code. Hopefully it emphasizes that it's mainly talking about right/left sides on an equation. You have to read pretty carefully to realize this:

// This gives 13i as an `r-value` (right side) and then is discarded (not stored)
9i + 4i;
// `x` is an `l-value` (left side). The previous `r-value` is assigned to it (stored)
let x = 9i + 4i;
// A function can only call an `l-value` because it has a storage location
// An `r-value` has no storage location and therefore cannot be called
f(x)
f(`r-value?`) // Doesn't work...how could you call it?

A glossary section with term definitions would probably be a good idea in the long run.

@mdinger
Copy link
Contributor

mdinger commented Jul 2, 2014

Also, could you edit the first comment of issue #97 so that it renders as a TODO list (like issue #1)

Done

@vks
Copy link
Contributor Author

vks commented Jul 2, 2014

f(r-value?) // Doesn't work...how could you call it?

You can actually have an r-value as an argument to a function: f(9i + 4i)

(This is pretty important in C++11 and it's move semantics, because r-values can be moved instead of copied (because they cannot be reused), which is more efficient.)

@mdinger
Copy link
Contributor

mdinger commented Jul 2, 2014

Interesting. Didn't think about that. Was thinking about cases like this:

13i; // Let's pass this to f next line
f(`previous line`) // can't because it was discarded

@japaric
Copy link
Member

japaric commented Jul 3, 2014

Ok, let's merge this for now, until we start working on the glossary (#97)

japaric pushed a commit that referenced this pull request Jul 3, 2014
Link to explanations of r-value, l-value and lint
@japaric japaric merged commit 704a37b into rust-lang:master Jul 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants