user-defined operators: a very modest proposal
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Nov 22 17:13:25 EST 2005
On Tue, 22 Nov 2005 13:48:05 -0800, Steve R. Hastings wrote:
> User-defined operators could be defined like the following: ]+[
[snip]
> Examples of use:
>
> m = m0 ]*[ m1
> m = m0]*[m1
That looks to me like multiplying two lists. I have to look twice to see
that the operands are merely m0 and m1 and not [m0] and [m1].
> m = m0 ]outer*[ m1
> m = m0]outer*[m1
That just looks weird.
Here is a thought: Python already supports an unlimited number of
operators, if you write them in prefix notation:
inner_product(m0, m1)
outer_product(m0, m1)
etc.
Here is some syntax that I don't object to, although that's not saying
much. In mathematics, there are operators of a plus sign within a circle,
multiply sign within a circle, etc. The closest we can get in plain ASCII
would be:
m0(+)m1
m0(*)m1
m0(-)m1
etc.
--
Steven.
More information about the Python-list
mailing list