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

tutorial: Compare closure argument patterns to match statements #4417

Closed
brson opened this issue Jan 10, 2013 · 7 comments · Fixed by #16257
Closed

tutorial: Compare closure argument patterns to match statements #4417

brson opened this issue Jan 10, 2013 · 7 comments · Fixed by #16257
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Jan 10, 2013

The explanation of argument patterns in closures is pretty dense. Maybe it could be explained better by comparing to a match statement.

See http://www.reddit.com/r/rust/comments/16b9wh/tutorial_question_destructuring_in_stack_closures/

@emberian
Copy link
Member

emberian commented Aug 5, 2013

And also let patterns

@pnkfelix
Copy link
Member

part of #11755

@steveklabnik
Copy link
Member

So much of this has changed, both with for, and with closures, that I don't know if this issue is still relevant. is it?

@pnkfelix
Copy link
Member

@steveklabnik there are a family of potential problems that are flagged in the reddit discussion. Here are the ones that I can identify with a quick skim:

  • The original poster did not see that the syntax &x within the closure's arguments was a pattern binding that performs a dereference of the input,
  • The fact that the closure itself takes a reference as input might be obscured by the fact that the closure doesn't have an explicit type signature (at least, that was one of huon's theories in his comment),
  • brson interpreted the discussion as a sign that drawing an analogy between match and the arguments to a fn could be helpful. (But !kibwen's comment points out that the patterns for fn arguments need to be irrefutable, which is an important distinction and thus I am not 100% sure an analogy with match will help.)

I'm not sure if this particular ticket is actionable on its own.

I would want to make sure that the guide covers the fact that &x means one thing in expression context (namely, "make a reference to the l-value x") and another thing in pattern context (namely, "dereference the input and bind the resulting value to x"). We cannot put that into the "Variable bindings" section of the current guide, since that precedes the section on "Pointers", but maybe just make sure that there is a TODO in the "Pointers" section that ensures we cover the distinction between an &x expression and an &x pattern.

@steveklabnik
Copy link
Member

maybe just make sure that there is a TODO in the "Pointers" section that ensures we cover the distinction between an &x expression and an &x pattern.

Cool. Agreed. Since I'm working on pointers right now, that's very timely!

cc #16119

@steveklabnik
Copy link
Member

I actually think I'm just going to make patterns their own section, after pointers. We haven't talked about anything more than just very basic usage, and ref at the very least deserves an explanation

@pnkfelix
Copy link
Member

pnkfelix commented Aug 1, 2014

@steveklabnik that is probably best; there are a lot of subtle details in terms of the distinction between how l-values are handled versus r-values.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Aug 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants