tags:

views:

178

answers:

1

I would like to add syntax to Jython to enable a nicer API for users. For instance, matrix libraries like NumPy would benefit from having both matrix and elementwise operations like Matlab's :* vs. * infix operators.

You can create a matrix in Octave using:

A = [ 1, 1, 2; 3, 5, 8; 13, 21, 34 ]

which is considerably nicer than NumPy's:

b = array( [ (1.5,2,3), (4,5,6) ] )

R uses formulas "y ~ x + z" for selecting variables in a matrix/data frame. This is considerably nicer than the alternative of ["y"] ["x","z"] or parsing the string "y ~ x + y".

More complicated examples can be implemented in Cython using Easy Extend. But EasyExtend doesn't work on the JVM.

What is the easiest way but reasonably robust way to add syntax to Jython? It would be nice to have a framework to implement entirely new language constructs or define mini languages within jython.

A: 

To the best of my knowledge there is not a macro / syntax expanding facility similar to EasyExtend, although the developer of EasyExtend has been working on some jython projects recently (including some which are similar to EE). I suppose you could write a preprocessor of some kind, but I would tend to suggest that syntax extension isn't terribly popular in the python world and you might have better success implementing your own DSL if you really need to.

Tim Gilbert