Maxima GUI in Common Lisp



Hi!

I have been researching possibilities for 'the ultimate Maxima GUI'.  
These are my findings:

*) It should be written in Common Lisp - this would allow the GUI to  
interact directly with the Maxima kernel. This is the biggest  
limitation of wxMaxima - it communicates with Maxima basicly as if a  
user would type in commands. A gui written in CL would allow features  
similar to Mathematica's 'Manipulate' command, which one of the  
better ways to explore mathematical concepts. Limitless possibilities  
arise from a GUI written in CL (running in the same image as Maxima,  
but a separate thread - gui is always responsive):
- departure from the 'terminal'-like input/output paradigm
- natural manipulation of expressions (reordering of terms, applying  
simplifications to parts of expressions in-place ..)
- 'preview' of various commands - a right click menu on an expression  
could display (calculated on the fly in another thread) resoults of  
various Maxima commands, eg: ratsimp, demoivre... then the user can  
select the simplification visually, based on results
- 'live' evaluation - (like Manipulate) a slider attached to variable  
would reevaluate the expression and display resoults in 'real- 
time'... because we are in common lisp, the expression in question  
would be parsed only once (and could also be compiled)
- the GUI can recieve result in Maxima's internal format and  
interpret them any way it wants

*) Best way to do a gui is via OpenGL. 'Big' widget toolkits like Qt  
or wxWidgets don't have very good bindings for CL - also they are a  
big dependency and Maxima GUI would benefit from 'custom' widgets  
(like sliders, plots..) more. There are great bindings for OpenGL (cl- 
opengl) and that way, the rasterization and drawing work is offloaded  
to the GPU, leaving more CPU for Maxima's computation. An OpenGL  
based gui also allows quick renderings of various vector (and raster)  
graphics via display lists and vertex arrays - a plotting/drawing  
system of Mathematica's quality is easily possible. Since rendering  
plots is done the same way as rendering the rest of Maxima's GUI,  
that means that including various graphics (like 2d math expressions)  
present in the GUI is also possible in the plot and the output looks  
the same.
When using OpenGL, one has to provide a native window. I've used cl- 
glfw bindings to create an OpenGL application with resizable window  
and mouse/keyboard events. GLFW library is a small cross platform  
helper library similar to GLUT (creates a native window on various  
OSs, so you can use OpenGL), but better - GLFW supports unicode  
keyboard input. Another possibility is to write OS specific backends  
with cffi to handle window opening and event handling (cffi to  
user32.dll ..).

*) Rendering 2D mathematical expressions. wxMaxima already does that  
well. This is possible in a Common Lisp OpenGL application also -  
TrueType TeX fonts (even unicode) are freely available. Rendering  
truetype fonts in OpenGL is tricky - C programs usualy use the  
FreeType library to rasterize fonts and then use them as textures.  
With CL there are two options - one is CFFI to FreeType, but the  
other is using zpb-ttf and cl-vectors Common Lisp libraries which  
have no external C dependancies (no need for FreeType). With these  
two libraries it is posible to rasterize TTF fonts into a CL array.  
The rest of the work is to upload these arrays into OpenGL textures  
living in graphic card's RAM and then quickly displaying them on  
demand. A nice wrapper just for this purpose exists: 'opengl-text' on  
http://github.com/Ramarren , which takes care of caching an uploading  
textures, so you can display TTF in OpenGL. Displaying a 2d  
mathematical expression is then only a matter of creating a bunch of  
'boxes'.
A gui written in CL can also provide intelligent code coloring -  
differentiating between bound and unbound variables, checking syntax  
correctness on the fly ...

The lisp implementations that could do such a gui are probably SBCL  
(but sbcl has no threads on windows yet) and ClozureCL, which are  
both very fast and work with CFFI. ECL has threads on windows, but I  
don't know how well it plays with CFFI..

To conclude - I think it is possible to implement a great 'live' GUI  
for Maxima in Common Lisp, which would depart from the usual input/ 
output paradigm that is currently used in Maxima,Mathematica,Maple  
and be very intuitive and fast to work with, pretty looking, easily  
extended (Maxima based RAD?) and better than what's currently out  
there. Of course it would take a lot of coding to do it. I have  
currently a basic application written that opens a resizable GL  
window, has some basic font rendering support (only vector based  
hershey fonts) and has a 'terminal' to evaluate CL expressions from  
within the running application. I have toyed with the idea of  
writting a CL based gui for Maxima myself, but with my knowledge of  
Common Lisp and Maxima internals, it would take ages... Perhaps  
someone interested/brave enough on this list will begin coding it.

Regards,
Ziga