On Sat, Aug 29, 2020, 2:24 PM Paul Moore <p.f.mo...@gmail.com> wrote:

> On Sat, 29 Aug 2020 at 18:04, Jonathan Fine <jfine2...@gmail.com> wrote:
> >
> > Paul Moore wrote:
> >
> >> But you don't give any reason why you'd want to do that. Why are you
> >> using subscript notation rather than a simple function call?
> >
> >
> > Good point. Consider
> >     >>> def f(*argv): pass
> >     >>> d = dict()
> >
> > Now compare
> >     >>> f(1, 2) = 3
> >     SyntaxError: can't assign to function call
> >     >>> d[1, 2] = 3
> >     >>> d[1, 2]
> >     3
>
> Obviously. As it says, you can't assign to a function call.
>
> > Item assignment (ie __setitem__) is the one thing that a function call
> can't do. If we want keywords in our __getitem__ and so on commands, then
> one route for item assignment is to allow
> >     >>> d[1, 2, a=3, b=4] = 5
> > as valid syntax.
>
> Again, obvious. But you still haven't given any reason why we would
> want to do that. No-one's arguing that these things aren't possible,
> or that the proposals can't be implemented. What I'm asking, and you
> aren't answering, is what is the use case? When, in real world code,
> would this be used?
>

I'd like to use syntax like this for defining a named mathematical
functions:

>>> f, g, h = mymath.funcs("f g h")
>>> x, y, z = mymath.vars("x y z")
>>> f[x] = x**2 + 2*x + 1
>>> g[x, y] = x**2 + x*y + y**2
>>> h[z] = f[z] + g[1, z]
>>> h[2]
15
>>> h[z=2]
15

Why? Because it looks like handwritten math. Far more pleasant for my
colleagues to read than lambda expressions and def statements.

I can already do most of this now of course (on fact, I have). But it'll be
far far easier to write, read, and maintain the supporting code with
function-like argument parsing in subscripts.

>
_______________________________________________
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/J4AYKCP3SIXUPQWGND3LM7RDVGKFCFUT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to