-
Notifications
You must be signed in to change notification settings - Fork 25
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
Ambiguity of the ... operator #18
Comments
What about |
@Haroenv |
The function f(...args) { console.log(JSON.stringify(args)); }
const g = f(1, ...);
g(2, 3); // [1, 2, 3] Since it is effectively transposed as: const g = (() => {
const fn = f;
const p0 = 1;
return (...an) => fn(p0, ...an); // <- transposition of `...`
}(); I have also considered allowing function f(...args) { console.log(JSON.stringify(args)); }
const g = f(1, ?...);
g([2, 3]); // [1, 2, 3]; As well as allowing function f(...args) { console.log(JSON.stringify(args)); }
const g = f(1, ...?);
g(2, 3); // [1, [2, 3]]; In which case |
I think that |
@nicolo-ribaudo It's also used for rest in function parameters, and function f(a, b, ...rest) {}
f(a, b, ...spread) {}
const [a, b, ...rest] = ar;
ar = [a, b, ...spread];
const { a, b, ...rest } = obj;
obj = { a, b, ...spread }; Therefore its highly ambiguous in partial application: const g1 = f(a, b, ...); // both rest and spread (not ambiguous)
const g2 = f(a, b, ...?); // is this a `...rest` or a `...spread`? If we were to support disambiguating the two, having
Otherwise we'd need a different syntax to disambiguate direction (i.e. In general I believe its simpler to just have |
Closing for now as the current proposal draft as removed support for the |
In case this gets re-opened, how about just using parens:
Parens are already commonly used to clear up syntax (e.g. It could also play well with types: |
I think |
I think having both f(❓) // x => f(x)
f(1, ..., 2) // (...x) => f(1, ...x, 2)
f(1, [...], 2) // (...x) => f(1, x, 2)
f(❓1, ...❓2, ...) // (x, y, ...z) => f(x, ...y, ...z) (I use Ambiguity only occur if use both f(...%,...) // syntax error!
f(...%1,...) // much clear what we want
// actually having multiple % is also confusing, we'd better also ban it
f(%, ..., %) // what this mean?
f(%1, ..., %1) // (x, ...y) => f(x, ...y, x) or
f(%1, ..., %2) // (x, y, ...z) => f(x, ...z, y) or
// (x, ...y) => f(x, y.slice(0, -1), y[y.length - 1]) ??? Current proposal use PS. the last semantic could be supported in the future by introducing PPS. I use
|
I think the
...
operator could lead to confusion, being it already used for array destructuring and function variadic arguments.My proposal is to use something more like
?...
, that would be consistent with the other proposal #5 on the positional placeholders.The text was updated successfully, but these errors were encountered: