Discussion: new operators for numerical computation

Bernhard Herzog herzog at online.de
Thu Jul 20 12:49:59 EDT 2000


Tim Hochberg <tim.hochberg at ieee.org> writes:

> aahz at netcom.com (Aahz Maruch) writes:
> 
> > Huaiyu Zhu  <huaiyu_zhu at yahoo.com> wrote:
> > >
> > >        matrix          element      names (with prefix m or e)
> > >          +               .+            add
> > >          -               .-            sub
> > 
> > I am strongly opposed to operators of the form ".+".  What happens if
> > take an expression of the form "5.+matrix"?  No, that goes against the
> > Python rule of having zero ambiguity.
> 
> Note that if .+, etc are matrix operations, there is no ambiguity

AFAICT, there's no ambiguity at all, at least from the parser's point of
view.

   5.+matrix 

already is legal python and equivalent to

   5. + matrix

Introduction of a .+ operator won't change that.

> since (5.)+A, etc. is not a legal expression,

It's syntactically legal python. It may lead to runtime errors, of
course, but that doesn't have anything to do with matrices in
particular.

> so the only interpretation is 5.(+A).

You want to call a float?

> Still it looks confusing. 

Agreed, but the confusion comes from allowing floating point literals to
end or start with the decimal point (2.+.5 is valid python).

The best way to avoid confusion is to surround all binary operators (or
at least the new .-operators) with whitespace. "5 .+ matrix" only has
one interpretation if .+ is a legal operator.


-- 
Bernhard Herzog   | Sketch, a drawing program for Unix
herzog at online.de  | http://sketch.sourceforge.net/



More information about the Python-list mailing list