Inconstistency with empty splat and commas
vendethiel opened this issue · 8 comments
coco -bce "[..., a]=[0 1]; [..., b,]=[0 1]; a == b"
true
I don't see inconsistency there. Single trailing comma is simply ignored as in JS and many other languages:
$ node
> [0]
[ 0 ]
> [0,]
[ 0 ]
> [0,,]
[ 0, ]
Agreed.
Uh. That seems anti-natural since it's a destructuring pattern more than an array. What's the use case where you put a trailing comma at the end of a destructuring pattern ? (I never used a single one in coco/coffee/whatever)
It seems like a valid explanation tho ...
What's the use case where you put a trailing comma at the end of a destructuring pattern ?
When one span multiline I guess:
js> [ a,
b,
] = [
0,
1,
]
[0, 1]
Admittedly not very useful in Coffee families since we don't need those commas at all.
My exact point.
I also find it inconsistent with array voids : [,]
is [void]
and [,,]
is [void void]
In those cases the commas aren't optional, indicating empty items.
js> [,].length
1
js> [,,].length
2
coco> [,].length
1
coco> [,,].length
2
Yup, so [,,]
is not consistent with [4,]
Comparing those two is pointless.
[,,]
is short for [void, void,]
and consistent with [4, 4,]
etc.