-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
SI-8044 Allow binding backquoted varid in patterns #4935
Conversation
I'm a little bit worried about this adding another rule for people to remember.
|
The argument for the defence is that it is nice to have a quoting mechanism that works in all cases is nice if you're writing a code generator that targets pattern syntax. (IIRC that was the motivating use case behind the bug report.) That said, I'm do find the prosecution's arguments persuasive. Reasonable doubt goes the way of the status quo. @som-snytt WDYT, a dozen days later? |
The defense would highlight on cross-examination that people who are liable to be confused are already confused on day one by Since that is the only context that suffers from weird rules, after they learn about backquoting the varid Backquotes have no other special powers, unless you adopt my idea that backquoted underscore introduce a fresh name. If regularity is a virtue, then why not allow Most importantly, it makes possible what is otherwise impossible (and also reasonable). My use case was varids like |
We've discussed this during our biweekly world domination meeting, and we find for the case for more backticks. So, we're in favor of your PR, buuuuuut:
|
Currently it accepts only backquoted varids, only because "varid" is a thing. If anything goes, then I think @retronym 's original suggestion to allow binding X without quotes is valid, and if that's true, can I also bind operators like star, with or without backticks? I might have just persuaded myself that anything goes. case Seq(* @ _*) => *
case `X`: Int => X
case C(`X`) => X
case C(`X`: Int) => X I just ran out of clever things to say. I can imagine the SO questions. I'll go code up the Abide rule for "no backticks in type pattern." Also, don't tell Dad. |
@adriaanm what I meant (@som-snytt points out that Jason mentions it on the ticket): for full regularity |
I'll add an improvement commit for that soon, and see how it looks. |
3f01657
to
0786944
Compare
Added |
This PR also partially addresses "how do I define multiple vars with non-varid names?" http://stackoverflow.com/a/12815725/1296806
It's not super-great. The fellow on SO had the intuition that backquotes should invert the test for varid:
So that didn't error b/c I just defined A and B; it's a no-op match here. But suppose it introduced A and B because of the backquotes. |
0786944
to
abc07dd
Compare
Rebased just because it caught my attention. Boy, it sure would be nice if it didn't catch my attention again. |
Previously, a varid could not be backquoted, so that it was not possible to introduce variables with names such as `type` in a match expression. This commit allows backquoted varids in `case x @ _` and `case x: Int`. In neither position is a stable id accepted, that is, an id with leading uppercase. Therefore, this commit merely relaxes the backquoted varid to be taken as a normal varid in these contexts.
Allows arbitrary identifier in `X @ pat`, including non-varids. This goes to regularity. Users of this syntax are not likely to be confused by the "backquoted var id is stable" rule. Also for sequence pattern, `X @ _*`.
abc07dd
to
1e565d8
Compare
Rebased and added test for
That is actually the most common use case for I hope @adriaanm is not on vacation. I guess he accrues both US and Euro vacadays. |
Timeout on docs.comp. |
/rebuild oh, ci! |
LGTM |
Previously, a varid could not be backquoted, so that it was not
possible to introduce variables with names such as
type
in amatch expression.
This commit allows backquoted varids in
case x @ _
andcase x: Int
. In neither position is a stable id accepted,that is, an id with leading uppercase.
Therefore, this commit merely relaxes the backquoted varid to
be taken as a normal varid in these contexts.