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

Support multiple parameters to pattern matching #36

Closed
aem opened this issue Jul 8, 2017 · 6 comments
Closed

Support multiple parameters to pattern matching #36

aem opened this issue Jul 8, 2017 · 6 comments

Comments

@aem
Copy link

aem commented Jul 8, 2017

While JavaScript doesn't have a formal concept of a tuple, matching multiple values in one statement rather than using nested match statements would be nice. A proposed syntax using commas draws from Swift:

match (a, b) {
  { x }, { t }: // handle case
  { y }, { z }: // handle case
  else: throw new Error("unmatched")
}

Without the multiple match syntax, this code expands to the following:

match (a) {
  { x }: match (b) {
    { t }: // handle case
    else: throw new Error("unmatched")
  }
  { y }: match (b) {
    { z }: // handle case
    else: throw new Error("unmatched")
  }
  else: throw new Error("unmatched")
}
@7fe
Copy link

7fe commented Jul 8, 2017

implicit fall through and && and || has been discussed here #7

EDIT: trotyl good catch. I am leaving this here although you are right they are different.

@trotyl
Copy link

trotyl commented Jul 8, 2017

@limeblack This is not talking about fall through, but matching multiple parameters at the same time.

@trotyl
Copy link

trotyl commented Jul 8, 2017

But this is not relevant to || at all, #7 is talking about matching one parameter with several patterns, but this is for marching several parameters with their own patterns.

@aem aem changed the title Support multiple pattern matching Support multiple parameters to pattern matching Jul 8, 2017
@aem
Copy link
Author

aem commented Jul 8, 2017

Yeah, multiple simultaneous parameters to the match. I updated the title to be a bit more clear

@leonardiwagner
Copy link

leonardiwagner commented Jul 10, 2017

@aem Seems you are proposing a solution for a problem which doesn't exists. You read multiple arguments in a function call function(a, b, c, d) as Array (eg.: this.arguments).

There is no sense to try match a data structure (tuples) which doesn't exists on JavaScript. After all it will be a quickfix behind the scenes to translate it to Array, If you want to achieve a data structure match in a real world scenario is much more sane calling matches([a, b, c, d]) and checks:

[{a: 1, b: 2, ...xs}]: {},
[{a: 'jordan', b: 'marie', ...xs}]: {},

rather than matches(a, b, c, d) , is even easier to read the matches

@zkat
Copy link
Collaborator

zkat commented Mar 25, 2018

Hey y'all! #65 has gotten merged, and a lot of issues have become irrelevant or significantly changed in context. Because of the magnitude of changes and subtle differences in things that seem similar, we've decided to just nuke all existing issues so we can start fresh. Thank you so much for the contributions and discussions and feel free to create new issues if something seems to still be relevant, and link to the original, related issue so we can have a paper trail (but have the benefit of that clean slate anyway).

As far as multiple patterns go: we decided to move this feature into the "Beyond This Spec" section. It -would- be very nice, and my earlier draft of the proposal included this (both in AND and OR forms), but after discussions and a bit of bikeshedding, it became clear that this would be a much bigger discussion, and I'd rather not block the initial proposal on this, since I consider it non-essential (based on how this sort of feature is not nearly universal in pattern matching implementations).

@zkat zkat closed this as completed Mar 25, 2018
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

6 participants