[Numpy-discussion] [help needed] associativity and precedence of '@'

Alexander Belopolsky ndarray@mac....
Mon Mar 17 20:25:30 CDT 2014


On Mon, Mar 17, 2014 at 8:54 PM, Nathaniel Smith <njs@pobox.com> wrote:
>
> Currently Python has 3 different kinds of ops: left-associative (most
> of them), right-associative (**), and "chaining". Chaining is used for
> comparison ops. Example:
>
>    a < b < c
>
> gets parsed to something like
>
>    do_comparison(args=[a, b, c], ops=[lt, lt])


The actual parse tree is more like Compare(a, [lt, lt], [b, c]) with the
first aruments playing a distinct role:

>>> ast.dump(ast.parse('a<b<c'), annotate_fields=False)
"Module([Expr(Compare(Name('a', Load()), [Lt(), Lt()], [Name('b', Load()),
Name('c', Load())]))])"

Your idea is very interesting and IMO, worth considering independently from
the @ operator.  I always wanted a vector "between" operator to be
available in numpy as low < x < high.

The only problem I see here is with mixed types, but we can follow the pow
precedent [1]: "Note that ternary pow() will not try calling __rpow__()
(the coercion rules would become too complicated)."


[1]
http://docs.python.org/3/reference/datamodel.html#emulating-numeric-types
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20140317/61523374/attachment.html 


More information about the NumPy-Discussion mailing list