user-defined operators: a very modest proposal

Dan Bishop danb_83 at yahoo.com
Tue Nov 22 18:24:06 EST 2005


Steve R. Hastings wrote:
> I have been studying Python recently, and I read a comment on one
> web page that said something like "the people using Python for heavy math
> really wish they could define their own operators".  The specific
> example was to define an "outer product" operator for matrices.  (There
> was even a PEP, number 211, about this.)
>
> I gave it some thought, and Googled for previous discussions about this,
> and came up with this suggestion:
>
> User-defined operators could be defined like the following: ]+[
>
> I'm not any kind of language design expert, but this seems to me like a
> syntax that would be easy for Python to recognize.  Because the square
> braces are reversed from the usual "[]" order, this should not look like
> any currently-valid code.

Is [a,b]+[c] the concatenation of two lists, or a single two-element
list containing a and b ]+[ c?

> And square braces, IMHO, do not fail the "low-toner printout" test.

They do.  Just yesterday I printed some code in which some of the
square braces didn't show up.




More information about the Python-list mailing list