[Python-ideas] Infix matrix-multiply, but not general infix operators?
Chris Angelico
rosuav at gmail.com
Fri Mar 21 06:43:48 CET 2014
On Fri, Mar 21, 2014 at 4:01 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 03/20/2014 08:40 PM, Andrew Barnert wrote:
>>
>>
>> Also, imagine what it would look like to chain these:
>>
>> spam spam eggs baked beans spam spam
>>
>> Maybe the parser can figure out that the spam, baked, and spam are
>> operators and the spam, eggs, beans, and spam are operands, but what
>> hope does any human have?
>
>
> Why would spam be able to be both a variable and an operator? Hmm, perhaps
> because of the first-class citizen thing -- so the leading grit says "make
> it work" and without it is just passing it around.
If the creation of an operator is done by putting something into the
current namespace, then it has to be available as some sort of object.
On the other hand, if it's something done as a declaration, or a
pre-import keyword mapping, then it should be a keyword (like other
word operators, "if" and "else" and such), and unavailable for
assignment.
In theory, this could be done as:
from __aether__ import spam as operator
where "as operator", instead of specifying the name to bind to,
specifies that it be something other than a name. (Preferably, it
should use a keyword, rather than "operator", which is a valid name.)
This would go immediately under future statements, and would affect
the compilation of that module: any instance of the word "spam" is now
a keyword operator, so the above would be invalid. I'm still not
convinced it would be a good thing, but this at least gives a
per-module way to create operators.
ChrisA
More information about the Python-ideas
mailing list