[Python-ideas] Operator for inserting an element into a list
cs at cskk.id.au
Fri Jun 15 21:44:22 EDT 2018
On 16Jun2018 02:42, Mikhail V <mikhailwas at gmail.com> wrote:
>Now I have slightly different idea. How is about special-casing of this
>as a shortcut for append:
>L = item
>Namely just use the fact that empty slice is SyntaxError now.
Now we're just making typing errors into working code.
Also, that isn't an empty slice. That's a _missing_ slice. An empty slice has
While genuinely new syntax needs to land in such a gap (because otherwise it
will break working code), new syntax needs a much highly value than new
meanings for existing operators.
Some things _should_ be syntax errors. Particularly things which may be typing
errors. Suppose I'd meant to type:
L = item
Silent breakage, requiring runtime debugging.
>I understand this is totally different approach than operator
>overloading and maybe
>hard to implement, but I feel like it looks really appealing.
>And it is quite intuitive imo. For me the syntax reads like:
>"add new empty element and this element will be "item".
The term "new empty element" is a nonsense term to me.
If you mean "replace an empty slice at the end of the list with a new element",
that can already be written:
Cumbersome, I accept. But I've got a .append method.
Cameron Simpson <cs at cskk.id.au>
More information about the Python-ideas