[Python-ideas] The @update operator for dictionaries

Anders Hovmöller boxed at killingar.net
Sat Mar 9 15:13:37 EST 2019

Why are you continuing to insist on using the symbol "@" after all these problems have been pointed out I wonder? Just suggest $ or something else that is a syntax error today and we can move on with discussing the merits of the underlying idea itself?

/ Anders 

> On 9 Mar 2019, at 20:03, Jonathan Fine <jfine2358 at gmail.com> wrote:
> Acknowledgement of an error, and clarification of behaviour of '@b' vs
> '@ b'. I claim that once '@b' is accepted as an operator, the
> behaviour is perfectly natural and obvious.
> In a previous post, I mispoke. I should have written
>    a at b+1
> is valid Python before and after, but with different syntax.
>    (a @ b) + 1 # Before - operator is '@'.
>    a @b (+1) # After - operator is '@b'.
> Chris Angelico kindly pointed out that my Before value was wrong.
> Thank you, Chris.
> Chris also correctly points that
>    '@ b' is parses as the '@' operator followed by the identifier 'b'
>    '@b' parses as above (BEFORE)
>    '@b' parses as the '@b' operator (AFTER)
> He then correctly says that in my proposal the lack of whitespace
> after an operator can cause the operator to absorb a following
> identifier.
> However, something similar ALREADY happens in Python.
>>>> a = nota = True
>>>> not a
>    False
>>>> nota
>    True
> Today, whenever a Python operator ends in a letter, and is followed by
> an identifier, white space is or some other delimiter is required
> between the two. Python, rightly, refuse to guess that 'notary' might
> be 'not ary'.
> Here is another example
>>>> e = note = None
>>>> e is not e
>    False
>>>> e is note
>    True
> This is not quite what's happening with '@b'. With 'is not e' the
> following identifier 'e' absorbs the 'not' from the operator to create
> 'note'.
> And finally
>>>> False is not None
>    True
>>>> False is (not None)
>    False
> The 'natural language' operators appear in
> https://docs.python.org/3/reference/expressions.html#operator-precedence
> In my suggestion, '@' consumes for as long it can, first a letter, and
> then name characters. This is exactly the same as with 'a' or 'b'.
> I think this is a problem, but not nearly so bad as Chris suggests.
> Some people have argued that the proposed semantics for dict + dict
> are natural and obvious, once the behaviour of Python elsewhere is
> understood. I claim the same for '@b' and '@ b', once we allow '@b' as
> an operator (which was the whole purpose of the proposal.
> By the way, it's likely that most users won't know that '@' by itself
> is an operator, until they come to use matrices.
> -- 
> Jonathan
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

More information about the Python-ideas mailing list