>
> "Self-explanatory". This is how we got Perl and APL o_O


What I mean is that if you already know the destructuring syntax, then it’s
pretty clear what it means. If you already know existing syntax, / isn’t
suggesting of anything. The only related syntax is for declaring
positional-only arguments, which is very uncommon and I usually have to
look up.

Using arbitrary unrelated symbols because they happen to be available is
how we got Perl.


What do we need the star for?
>
>     x, *... = items
>     x, ... = items
>
> Convince me that adding another meaning for the star symbol is a
> good idea


I don’t see it as another meaning for the star symbol. It’s an extension to
an existing meaning. The only argument I can give is based on intuition
having written Python for years.

>From a code reader’s perspective, you often guess meaning based on the rest
of the language and the context rather than memorizing the entire
grammar.  Consider
the following:

x, *remainder = items  # 1
x, *_ = items  # 2
x, *… = items  # 3
x, … = items  # 4

(1) and (2) are valid syntax. They are how one would currently write the
concept under discussion, other than the optimizations of not allocating a
list or advancing the iterator.

(3) has a pretty clear analogy to (2). If you basically know Python 3.10
syntax and the interpreter is telling you that (3) is valid Python code,
there are two thing this could possibly mean:

(a) [wrong] … is an identifier that can be assigned to, similar to _. Its
value will be the rest of the list/iterator, but given what … means in
English and other Python code, you’re being told by the code author that
you don’t care. The main difference with (2) is that _ is used in
internationalization, which makes assigning to it a bad idea in some code.
(b) [correct] You recall that … is actually a singleton object that cannot
be assigned to. This suggests the intended meaning in this thread. Since …
cannot be assigned to, the rest of the list/iterator is probably not being
used for anything.

What’s notable about this is that the wrong interpretation is still mostly
correct, eg if this syntax is used on a list. With (4), you could have the
same misunderstanding about whether … is a special-case identifier name,
but then your interpretation becomes completely wrong as opposed to
slightly wrong.

In other words, * is telling you that this is variable-length object
destructuring syntax, and it has a similar meaning to (1) and (2).

So I think your question is backwards. Omitting the * means you are
genuinely introducing a new syntax for something that is extremely similar
to existing syntax, as opposed to slightly altering existing syntax for a
slightly different meaning.

Best wishes,
Lucas
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/GJWREIR3N5SU7F6Q2BHUCDZWH3LSHBQ3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to