Improve pattern-matching
Closed this issue · 4 comments
In the following pattern
{x,y:[a,b]} = {x:1,y:[2,3]}
it's expected that
x == 1, y == [2, 3], a == 2, b ==3
but y is undefined, despite _ref1 contains y
a: 2, b: 3, x: 1, _ref: { x: 1, y: [ 2, 3 ] }, _ref1: [ 2, 3 ]
Yeah, because it's only the key in the case of a deep destructuring (not "pattern match"). We'd need as-pattern - See also #363.
Is there any reason not to do deep destructure? Formaly it's not pattern-matching anyway because
{x,y:[2,b]} = {x:1,y:[2,3]}
will not work.
not to do deep destructure
We do deep destructure -- we just don't provide the intermediate objects. The comments in the issue I linked seem to indicate that a series of destructuring is the correct answer
Formaly it's not pattern-matching
Indeed, hence what I said :
(not "pattern match").
we just don't provide the intermediate objects
Why? What's wrong with providing intermediate objects? Of course it is possible to solve above issue this way
{_, y} = {x,y:[a,b]} = {x:1,y:[2,3]} # y = [2,3]
but what is the reason to do the same work twice and have more auxiliary variables?
The issue you linked seems to describe different question which is solved in CS
z = {x,y:[a,b]} = {x:1,y:[2,3]} # z = {x:1, y:[2,3]}