3 ms·
Roughly, that is true. However, the actual pattern matching rules are a bit more complex: () # Makes a zero-tuple. The parens are required. 2,
by raymondh 4y ago
Roughly, that is true. However, the actual pattern matching rules are a bit more complex:
() # Makes a zero-tuple. The parens are required.
2, # Makes a one-tuple.
(2,) # Makes a one-tuple. The parens are optional.
[2] # Makes a list of size one.
[(2)] # Also makes a list of size one.
[2,] # Also makes a list of size one.
f(x, y) # Call a function with two arguments.
f((x, y)) # Make a 2-tuple and call a function with one argument.
- carapace 4y agoYeah, you're right, of course. I should have mentioned the concept of "comma operator" is a heuristic, not something from the grammar or semantics. BTW, kind of a tangent, I've always assumed (but not checked) that every "()" literal evaluates to one singleton zero-tuple, do you know if that's true?
- raymondh 4y agoIt was, but that is not guaranteed and may stop being true due to work on subinterpreters, new memory managers, and heap types. Also, it used to be true that ``frozenset() is frozenset()``, but that was lost in the war on singletons and global state.
- carapace 4y agoAh, cheers! You're a treasure!