3 ms·
> First off, you're plain wrong about Python As pointed out by minitech, this syntax was allowed in some versions of Python 3 but that was a bug which has sinc
by abbeyj 5y ago
> First off, you're plain wrong about Python
As pointed out by minitech, this syntax was allowed in some versions of Python 3 but that was a bug which has since been fixed. I didn't run into this bug in the version of Python 3 that I used for testing so I had no idea of the bug's existence.
> I doubt the veracity of the other examples
Python 3.10: https://godbolt.org/z/Po7K7cvY8 https://godbolt.org/z/Po7K7cvY8
Ruby 3.0.2: https://godbolt.org/z/Ke5oWzaW3 https://godbolt.org/z/Ke5oWzaW3
C++ (clang 13.0.0): https://godbolt.org/z/zd5MfM4Mo https://godbolt.org/z/zd5MfM4Mo
Go (amd64 gc 1.17): https://godbolt.org/z/KrEsKaTjq https://godbolt.org/z/KrEsKaTjq
Lua (luac 5.3.3): https://ideone.com/irl89j https://ideone.com/irl89j
Perl (perl 2018.12): https://ideone.com/YZcCAC https://ideone.com/YZcCAC
> Honest question, are you aware of the comma operator and how it works?
I am. The existence of the comma operator is the reason that `console.log((a, b))` parses (and means something different than `console.log(a, b)`). If we consider a hypothetical version of JavaScript which does not have the comma operator then `console.log((a, b))` wouldn't parse at all! The comma there can't be the comma operator because we've removed that. And it can't be part of the function call because then the first argument to the function call would have to be `(a` which is obviously not a valid expression. And it can't be part of an array literal or an object literal because it isn't inside of `[]` or `{}`. That leaves us with no valid ways for this to parse.
You can usually add extra parentheses around any expression without changing the meaning. But "all the arguments to a function" is *not* an expression (except in the case where there happens to be exactly one argument). This is why it doesn't make sense to change `console.log(a, b)` into `console.log((a, b))`, why it doesn't make sense to change `console.log()` into `console.log(())`, and why it doesn't make sense to change `console.log(...a)` into `console.log((...a))`.