On Fri, Jul 10, 2020, 6:54 AM Jonathan Fine <jfine2358@gmail.com> wrote:
Hi All

SUMMARY
This 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. 


PRESENT
I 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) = None
    SyntaxError: can't assign to function call
and 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)] = value


My mind instantly went to the idea of using this syntax as a way write single line mathematical function definitions:

f[x, y] = x + y

The 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 + y

And calling them would use a different bracket type (parentheses):

>>> f(1,2)
3

...but these are surmountable hurdles.