_______________________________________________On Fri, Jul 10, 2020, 6:54 AM Jonathan Fine <jfine2358@gmail.com> wrote:Hi AllSUMMARYThis is a longish post. It looks at the idea in general terms, and outlines a way to get the desired semantics (by not syntax) with Python as it is today. And this would be forward compatible with the new syntax, if provided later.This post was filled with inspiring ideas for me. Thank you.PRESENTI like the idea of allowing>>> d[1, 2, 3, a=4, b=5]and will explore it further.First, we can already write>>> f(1, 2, 3, a=4, b=5)but that only works for the get operation. For set the present behaviour is>>> f(1, 2, 3, a=4, b=5) = NoneSyntaxError: can't assign to function calland I see no good reason to change that.Going further, I'd say that allowing both>>> d[something] = value>>> value = d[something]is essential to the difference between f(something) and d[something]. Both are expressions, but only one of them can be assigned to.Here goes. First syntax.>>> value = d[K(1, 2, 3, a=4, b=5)]>>> d[K(1, 2, 3, a=4, b=5)] = valueMy mind instantly went to the idea of using this syntax as a way write single line mathematical function definitions:f[x, y] = x + yThe example function doesn't even require the suggested K() object since no kwargs or defaults are used.Of course one would need to instantiate any these single line functions using a little bit of boilerplate up top. But this could be when you provide the docstring:f = MathFunction("Simple math function")f[x, y] = x + yAnd calling them would use a different bracket type (parentheses):>>> f(1,2)3...but these are surmountable hurdles.
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/QKDZ4Y6KBIVEFJ34ITLZHUT4IPE3QBBQ/
Code of Conduct: http://python.org/psf/codeofconduct/