[Numpy-discussion] Possible new multiplication operators for Python

Andrew Dalke dalke@dalkescientific....
Sun Aug 17 14:00:01 CDT 2008


Fernando Perez wrote:
>  For something as big as this, they would
> definitely want to work off a real pep.

What might be interesting, for those who want to experiment
with this syntax, is to take my Python parser for Python
(python4ply - http://www.dalkescientific.com/Python/python4ply.html )
and add support for the proposed syntax.  It's only a
grammar change and it shouldn't be that hard to change the
syntax tree so that a proposed "~+" or whatever gets converted
to the right method call.  Python4ply generates PVM byte code,
so the end result is code that works with the existing Python.

You could even be adventurous and map things like

    a \power b

into binary operators, perhaps named "__op_power__"

It's loads of fun to tweak the grammar.  My tutorial
even walks through how to add Perl-like syntax for
regex creation and match operator, to allow


for line in open("python_yacc.py"):
     if line =~ m/def (?P<name>\w+) *(?P<args>\(.*\)) *:/:
         print repr($1), repr($args)


   :)


>> LR: It would be great to use unicode math operators.

Though if you want to experiment with this .. I make
neither guarantees nor warrantees about Unicode support
in what I did.  I don't even support the encoding hint
that Python code can have.



				Andrew
				dalke@dalkescientific.com




More information about the Numpy-discussion mailing list