Skip to content

Document @ binding syntax for pattern matching #7173

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

Closed
kvanbere opened this issue Jun 16, 2013 · 10 comments
Closed

Document @ binding syntax for pattern matching #7173

kvanbere opened this issue Jun 16, 2013 · 10 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@kvanbere
Copy link

Pattern matching binding syntax is not intuitive and requires documentation, as evidenced by the original issue below

Original

Sometimes it is desirable to be able to bind the entire pattern matched to a separate variable. Haskell uses @ for this, and it works nicely.

Consider input (1,2) fed into...

match vector {
  c@(a, b) => ...
}

...where c = (1,2), a = 1 and b = 2.

@huonw
Copy link
Member

huonw commented Jun 16, 2013

This actually exists now:

rusti> match (1,2) { c@(a,b) => println(fmt!("%? %? %?", a, b, c)) }
1 2 (1, 2)

@kvanbere
Copy link
Author

The tutorial lacks documentation on this. Could this ticket represent the task of adding such documentation?

@Aatch
Copy link
Contributor

Aatch commented Jun 16, 2013

@kvanberendonck I have edited your issue to be for documentation.

@sanxiyn
Copy link
Member

sanxiyn commented Jul 30, 2013

There was a discussion to change this from @ to something else: https://mail.mozilla.org/pipermail/rust-dev/2013-May/003989.html

@emberian
Copy link
Member

emberian commented Nov 4, 2013

This still needs doing. Shouldn't be too hard.

@lilyball
Copy link
Contributor

lilyball commented Dec 4, 2013

This probably doesn't need doing anymore, since @ is being removed.

@huonw
Copy link
Member

huonw commented Dec 4, 2013

@kballard hm? Is the pattern-matching @ being removed?

@lilyball
Copy link
Contributor

lilyball commented Dec 4, 2013

@huonw No, I meant @-boxes are going away, so there's no more need for a@@b in match. I suppose I was unclear; I was responding to @sanxiyn's comment and link to the ML suggesting that the match binding syntax should change.

@whatisaphone
Copy link
Contributor

This is now documented in both the tutorial and the manual

http://static.rust-lang.org/doc/master/tutorial.html#pattern-matching
http://static.rust-lang.org/doc/master/rust.html#match-expressions

It can probably be closed.

@alexcrichton
Copy link
Member

Thanks for the tip @johnsoft!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

8 participants