Skip to content

Why not more connection to destructuring? #2

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
domenic opened this issue Jul 3, 2017 · 5 comments
Closed

Why not more connection to destructuring? #2

domenic opened this issue Jul 3, 2017 · 5 comments
Assignees

Comments

@domenic
Copy link
Member

domenic commented Jul 3, 2017

When people theorized about pattern matching syntax in the past, it was always very related to destructuring, using the same syntax in most cases. I can appreciate there are probably reasons to depart, but I think it'd be useful to have a section explaining the connection, or lack thereof.

@domenic
Copy link
Member Author

domenic commented Jul 3, 2017

I guess there is more connection than I thought on first glance. The comments

  // Basically ObjectBindingPattern with with optional rest element
  // binding

make it clearer.

I still was pretty confused by the special-casing for other patterns, so I think adding some explanation of how matching cannot be completely done via destructuring because you want to match values that are not objects or arrays would be helpful. That was where I got confused at first; I was under a vague impression that pattern matching just kind of automatically fell out of destructuring, so seeing all the other stuff for literals and identifiers was confusing.

That confusion might be unique to me though. Feel free to close if you think it's clear enough as-is.

@bterlson
Copy link
Member

bterlson commented Jul 3, 2017

I should add more about this topic. Essentially if you limit the patterns to just the array and object patterns you have what you'd expect. This proposal takes a few further steps because they're very very useful for pattern matching in practice.

@bterlson bterlson self-assigned this Jul 3, 2017
@dmitriid
Copy link

dmitriid commented Jul 4, 2017

Pattern matching with destructuring is invaluable when you have it everywhere, especially in function calls. In JS syntax it would be something like

function f({x: "A", y}) {
  // incoming arg immediately destructured into x and y
  // *and* matched
  console.log("A")
}
function f({x, y: "Y"}) {
  // incoming arg immediately destructured into x and y
  // *and* matched
  console.log("Y")
}
// etc.

I guess this is what people would love to have, but, I guess, is impossible to properly implement in JS

@bterlson
Copy link
Member

bterlson commented Jul 5, 2017

@dmitriid you raise a good point in that if we want to use pattern matching machinery to create multi-methods or similar syntax that overlaps closely with destructuring, you will really want some alignment between the syntax. Good feedback for #17, #14, possibly others.

@chriskuech
Copy link

#160

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

No branches or pull requests

4 participants