[Python-Dev] Re: [Fwd: Discussion: Introducing new operators formatrix computation]

python@horizon.com python@horizon.com
19 Jul 2000 08:22:40 -0000

ESR was kind enough to suggest that this idea was worthy of a larger audience,
so here is my Very Humble Opinion Indeed...

(My knowledge of Python is limited to buying the O'Reilly book and meaning to
read it one of these days, so I may be missing something REALLY elementary here.)

But if you want extensible infix operators without burdening people trying
to read the code too much, consider this:

For each existing operator #, there is an infinite family of user-definable
operators @#, @@#, etc.  These get progressivley less readable, so I don't
think you'd *want* to go past @@, but hey, it's there if you want.

Each one has the same precedence and associativity as the bare operator #, so
there are no new rules for anyone to learn.  "a @* b * c @@* d" would
associate to the left as usual, producing "((a @* b) * c) @@* d".

You should probably extend this to unary operators, so someone could, for example,
define unary @- to be complex conjugate.

An alternative precednece rule would put * > @* > @@* > ... > + > @+ > ...,
which also avoids requiring people to learn much of anything new, but
I think people trying to write parsers would object strenuously to an infinite
number of precedence levels.

You need some way to define all of these functions, but I assume that's
just a Small Matter of Programming for the uber-studly programmers here,
leaping from tree to tree in the mighty forests of British Columbia...

Oh wait a minute, I'm sorry.  That's just getting silly.

A language I worked on a Long Time Ago used backquotes to turn operators
into normal functions so a + b was `+`(a,b), and the syntax was also used
when defining such functions, but I'm sure Python has some existing scheme
for referring to built-in operators that could be extended.

Anyway, just food for thought.

(If that isn't enough extra operators, you can also add *@.  And then even @*@.
@@*@ and @*@@ are for the terminally masochistic, and anyone who'd go beyond that
should be kept away from computers and sharp objects until they're feeling better.)

"Better get a bu.}}}}NO CARRIER