Discussion: Introducing new operators for matrix computation

Paul Prescod paul at prescod.net
Thu Jul 13 22:14:41 EDT 2000


Huaiyu Zhu wrote:
> 
> ....
> 
> Point 1.  We _can_ assign a universal meaning to dot operators, as
> "componentwise operators".  For example
> 

There is another proposal for allowing these types of operatoins:

> [1, 2] .+ [3, 4]            # [4, 6]

[x+y; for x in [1,2], y in [3,4]]

> ["a","b"] .* 2              # ['aa', 'bb']

[2*x; for x in ['a','b']]

> {'a':1, 'b':1} .+ {'a':1, 'c':1}   # {'a':2, 'b':1, 'c': 1}

Addition isn't really defined for dictionaries.

Note that this feature is more general than a fixed list of operators:

[transpose(invert(x)); for x in ['a','b']]

> Point 2. If users in completely disjoint domains override a certain type of
> binary operators with incompatible meanings, is there great harm?  Providing
> a few operators for user adoptation might even prevent grotesque overriding
> of more core operators.  After all, there is almost endless supply of names
> for classes, modules, function and so on, but there is almost no binary
> operators free for adoption.

Most people prefer for Python code to be very visually consistent across
domains. Of course there is a tension with those who want to add
domain-specific features (as I have wanted in the past). Allowing new
grammars may be the best compromise.

-- 
 Paul Prescod - Not encumbered by corporate consensus
Simplicity does not precede complexity, but follows it. 
	- http://www.cs.yale.edu/~perlis-alan/quotes.html




More information about the Python-list mailing list