
On Jun 23, 2014, at 5:53, Stefano Borini <stefano.borini@ferrara.linux.it> wrote:
On Mon, Jun 23, 2014 at 10:24:53PM +1000, Chris Angelico wrote:
The obvious way to accept that would be to support keyword arguments, and then it begins looking very much like a call. Can you alter your notation very slightly to become LDA(Z=5) instead?
We certainly can, but I was wondering if such extension would be useful in other contexts. Also, with the function solution, you would lose the order of the entries. You can't distinguish foo(z=3, r=4) from foo(r=4, z=3)
That last problem is a more general one, which applies to function calls at least as much as to your proposed use case, and there's an open PEP (466) that could probably use more use cases to convince people. With that PEP, you wouldn't get {'z': 3}, {'r': 4}, but OrderedDict(('z', 3), ('r', 4)) or something equivalent. I think that would make the function-calling workaround much more usable. And it would definitely make your additional proposal a lot simpler: add kwargs--which then work exactly the same as in function calls--to getitem. There's also a proposal for namedtuple literals, which seems like it fit your use case a lot better (especially if, like a regular tuple literal, the parens were optional). Unfortunately, if I remember right, nobody was able to come up with a good enough solution to the semantic problems to make it worth writing a PEP. But you could find that in the archives and see if you can come up with a workable version of that idea.