On Mar 15, 2014, at 4:41 AM, Nathaniel Smith wrote:
> OPTION 1 FOR @: ... "same-left"
> OPTION 2 FOR @: ... "weak-right"
> OPTION 3 FOR @: ... "tight-right"
(In addition to more unusual forms, like 'grouping'.)
There's another option, which is to "refuse the temptation to guess",
and not allow X @ Y @ Z or mixing with any other operators. After all,
several have pointed out that it should be in parenthesis anyway, in
order to avoid likely confusion.
There's even a bit of precedent for something like this in Python:
>>> f(1, 2 for i in range(10))
File "<stdin>", line 1
SyntaxError: Generator expression must be parenthesized if not sole argument
I haven't seen this non-associative option come up in the discussion.
To be frank though, I don't think this is a good idea, but Nathaniel
wrote "In principle the other 2 possible options are ...", so I wanted
to mention this for completion.
My preference is for same-left. I rarely work with numpy, and it's more
likely that I'll see '@' used in a non-numpy context. That is, people
in general will see "@" as a sort of free-for-all operator, to use and abuse
as they wish. [1]
(For example, Pyparsing has a lot of operator overloads to help make
a grammar definition, and they make good sense in that context, but '<<'
for recursive definitions is perhaps past the edge.)
Someone looking at a "@", without any intuition on precedence or
associativity of matrix operations in a mathematical package, will
have to figure things out from the documentation or (more likely)
experimentation.
If and when that happens, then
> "Same-left" is the easiest to explain and remember, because it's just, "@
> acts like * and /".
Cheers,
Andrew
[email protected]
I came up with two possible ways people might (ab)use it:
1) since "@" is server-like, then a service resolver:
service = XMLRPCServer @ "http://localhost:1234/endpoint"
There's no real need for this, since there are other equally
good ways to structure this sort of call. But someone creative
might come up with a good example of using '@' to mean some
sort of routing. Interestingly, that creative person might
prefer right-associative, to support the 'natural'
("janet" @ "moria" @ "uunet" @ uucpserver).send(message)
rather than the inverted:
(uucpserver @ "uunet" @ "moria" @ "janet").send(message)
This would likely fall under the definition of "cute and
ignorable".
2) "@" in XPath indicates an attribute. An XML tree API might
support something like:
tree = load_xml_tree(...)
for node in tree.select("//item[@price > 2*@discount]"):
print node @ price, node @ discount
That might even be a reasonable short-hand, compared to, say, etree's
node.attrib["price"]
XML doesn't allow nodes as attributes, so that provides
no guidance as to what
node @ price @ 1950
might mean.
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion