Is it possible to mix Lisp and Maxima code in the same file and
have Maxima load, translate, and compile the file? I haven't been
able to do this
Here are simple examples with one lisp form and one maxima form, but
there can of course be many such forms in the file:
The following is lisp file can be loaded with load("foo.lisp");
=======foo.lisp=================
(in-package "MAXIMA")
(defun $joe (x) (+ x 1))
#$f(n):=block([ans:0],
for j:1 thru n do ans:ans+x^j,
ans)$
==============end foo.lisp=======
and you will be able to do
(C1) load("foo.lisp")$
(C2) joe(5);
(D2) 6
(C3) f(3);
(D3) x^3+x^2+x
The above file however will not compile, and the maxima function
f still acts as a regular maxima function. In order to translate
it to lisp so that the compiler can act on it do the following:
(C1) load("help.lisp"); /* see this file below */
(C2) :lisp (compile-file "foo.lisp")
(C2) load("foo.o");
=======foo1.lisp=================
(in-package "MAXIMA")
(defun $joe (x) (+ x 1))
(tr #$$f(n):=block([ans:0],
for j:1 thru n do ans:ans+x^j,
ans)$ )
========end foo1.lisp============
The helper macro 'tr' is defined in help.lisp (note
we also have to define send, since it is used by the double $$
sharp reader macro we use in the above. We will add that
function to maxima in the next release.
=========help.lisp========================================
(in-package "MAXIMA")
;; some patches to let the above mixed lisp and maxima work ok.
(defun send (a b) (if (eql b :tyi) (tyi a) (error "unknown send")))
(defmacro tr (u)
(and (consp u) (eq (car u) 'quote)
(BIND-TRANSL-STATE (translate-macexpr-toplevel (second u)))))
===========================================================
Please note that the translation from maxima to lisp is not guaranteed
to keep all the 'features' of the maxima language. If you are having
a problem with speed of your maxima level code, certainly you can
try translating and compiling it. You can also write critical portions
of your code directly in lisp which will almost certainly produce faster
code.
william schelter