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

Pattern matching limited to var declarations, not allowed in assignments #1324

Closed
scabug opened this issue Sep 5, 2008 · 2 comments
Closed

Comments

@scabug
Copy link

scabug commented Sep 5, 2008

Is pattern matching to variables only allowed during variable definitions, and not during var assignments?

E.g., this works:
val t = (1, 2)
var (a, b) = t
a = 1, b = 2

But,
var x = 10
var y = 20
(x, y) = t
Illegal start of definitio

Seems to be that pattern based assignment would also be quite useful???

Further comments: (from Burak on the mailing list)
This particular change would probably not require any changes to the matcher, rather to the frontend (parsing - desugaring - typechecking).

It would be translated as something like

var x = 10
var y = 20
match {
(x1, y1) => x = x1; y = y1;
}

The pattern matcher would never need to be aware of something being a mutable variable.

Burak

@scabug
Copy link
Author

scabug commented Sep 5, 2008

Imported From: https://issues.scala-lang.org/browse/SI-1324?orig=1
Reporter: johnmani
Assignee: @DRMacIver

@scabug
Copy link
Author

scabug commented Sep 8, 2008

@DRMacIver said:
As per discussion on mailing list, this is actually pretty complicated, particularly when combined with syntax sugar for updates. It will need a SIP.

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

No branches or pull requests

1 participant