Proposed new elementwise syntax

Rainer Deyke root at rainerdeyke.com
Thu Aug 10 19:07:53 EDT 2000


Here is the latest version of my proposed new syntax for elementwise
operations.

For current language syntax provides the following production rule for
binary operators "*", "/", "%":

m_expr: u_expr | m_expr "*" u_expr | m_expr "/" u_expr | m_expr "%" u_expr

I propose that this production rule be replaced by the following rule:

m_expr: u_expr | m_expr m_operation u_expr
m_operation: "~" m_operation | "*" | "/" | "%"

I propose the following semantics for the new syntax:

Expressions in the forms m_expr "*" u_expr, m_expr "/" u_expr, and m_expr
"%" u_expr retain their previous meaning.

Expressions in the form m_expr "~" m_operation u_expr trigger the following
behavior:
  The result of the m_expr and u_expr are coerced into compatible types as
    is normal for a multiplicative expression.
  If m_expr.__elementwise__ exists, the result of the expression is
    m_expr.__elementwise__(u_expr, lambda x, y: x m_operation y)
  Else, the result of the expression is
    u_expr.__elementwise__(m_expr, lambda x, y: y m_operation x)

Furthermore, I propose that similar additions be made to other classes of
binary operators where appropriate.

There should probably also be a way to specify elementwise operations for
built-in and C extension types, with elementwise operations defined for all
built-in sequences and mappings, but that is outside of the scope of this
proposal at this time.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games      -      http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list