On Tue, Jun 23, 2020 at 4:41 PM MRAB <pyt...@mrabarnett.plus.com> wrote:

> On 2020-06-23 22:50, Barry Warsaw wrote:
> > On Jun 23, 2020, at 14:31, Chris Angelico <ros...@gmail.com> 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
> >> special.
> >
> > 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.
> >
> +1
>

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
>  >>> Ellipsis = 0
>  >>> Ellipsis
> 0
>  >>> ...
> Ellipsis
>

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
> .Ellipsis:"?
>

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.

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/IO7KFDG3UWN5OWAKEV4BSYCECV4RYH42/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to