On 2020-06-23 22:50, Barry Warsaw wrote:
> On Jun 23, 2020, at 14:31, Chris Angelico <firstname.lastname@example.org> wrote:
>> I can't find it among the rejected alternatives, but was it considered
>> to use "..." as the wildcard, rather than "_"? It carries similar
>> meaning but its special case of "this will never be bound" is simply
>> preventing an error, rather than making one otherwise-valid name
> I thought of that too as I was reading the PEP, but forgot to add it to my notes. I do like ellipsis more than underscore here.
The problem is that ellipsis already has a number of other meanings, *and* is easily confused in examples and documentation with leaving things out that should be obvious or uninteresting. Also, if I saw [a, ..., z] in a pattern I would probably guess that it meant "any sequence of length > 2, and capture the first and last element" rather than "a sequence of length three, and capture the first and third elements". (The first meaning is currently spelled as [a, *_, z].)
So I'm not a fan. _ is what all other languages with pattern matching seem to use, and I like that case (x, _, _) resembles the use of (x, _, _) in assignment targets.
However, what if you wanted to match Ellipsis?
This could lead to bugs:
>>> Ellipsis = 0
Now you're just being silly. If you want to use Ellipsis as a variable you can't also use it to refer to the "..." token.
If you can have "case False:" and "case True:", should 'Ellipsis' become
a keyword so that you could have "case Ellipsis:"? Or do they have to be
"case .False:", "case .True:", in which case it could remain "case
I don't think this problem is at all bad enough to make "Ellipsis" a keyword. It is much, much less used than True, False or None.