Discussion: new operators for numerical computation

Alexander Williams thantos at chancel.org
Mon Jul 24 22:55:59 EDT 2000


Well, if I'm feeling Haskellish (and I am), I might suggest `op` as a
generalized method of converting a function from prefix op(x,y) to 
"x `op` y".  This begs the question of what to do with multi-argument
functions since Python doesn't support currying to the degree Haskell
does.  Still, for binary functions (/any/ binary functions), it works
as well as any of the current proposals and is easily generalizable.
That is:

Assuming you have instance x of class X, possessing method mult, you
can do "x2 `x.mult` y" and it converts logically to "x.mult(x2,y)".
Yes, its syntactic sugar, but it's keen anyway.

(Am I the only one that thinks the question of how to impliment Matrix
stuff is, at heart, goofy, and stems from some mathematicians being
too lazy to do it the OO way, which would be to give the Matrix class
an eMult method to do element-wise multiplication and which checks the
type its given to make sure its sensical before returning an instance
of Matrix with the proper values?  Yes, the syntax looks like:

>>> mRes = m1.eMult(m2)

... but its syntactically clean, doesn't require any jibber-jabber
with the core interpreter, and works.  Could Python make use of type
dispatch mechanisms?  Probably, bjut get the Types-SIG to produce a
typeful proposal for Python before you leap on it.  I'd rather have
real function currying supported internally than type dispatch.  Could
I make use of the ability to make any sequence of characters into an
infix operator?  Probably, but its a lot less important than other
things to me.)

-- 
Alexander Williams (thantos at gw.total-web.net)           | In the End,
  "I think sex is better than logic,                    | Oblivion
   but I can't prove it."                               | Always
  http://www.chancel.org                                | Wins



More information about the Python-list mailing list