Discussion:
Calling Maxima from Lisp (sbcl)
Knut Gjerden
2009-06-15 12:51:02 UTC
Permalink
Dear developers,

This is an update to the post by Bruno Daniel found here:
http://article.gmane.org/gmane.comp.mathematics.maxima.general/17602

In order to work with the newer versions of Maxima (5.18.1) and SBCL (1.0.29),
the code suggested by Mr. Daniel should be changed slightly:

----------------------------------------------------------
(defpackage :my-package (:use :common-lisp))
(in-package :my-package)

(let ()
(load "/Users/knutgj/Code/usemaxima/maxima-5.18.1/lisp-utils/defsystem.lisp")
;; This creates a lot of warnings in SBCL, but they seem to do no harm:
(load "/Users/knutgj/Code/usemaxima/maxima-5.18.1/src/maxima.system")
(funcall (intern (symbol-name :operate-on-system) :mk) "maxima"
:load :verbose t))


(let ()
(setf maxima::*load-verbose* nil)
(setf *debugger-hook* #'maxima::maxima-lisp-debugger)
(let ((input-stream maxima::*standard-input*)
(batch-flag nil))
(progn
(maxima::set-readtable-for-macsyma)
(setf maxima::*read-default-float-format* 'double-float))
(catch 'to-lisp
(maxima::initialize-real-and-run-time)
(intl::setlocale)
(maxima::set-locale-subdir)
(maxima::adjust-character-encoding)
(maxima::set-pathnames)
(when (boundp 'maxima::*maxima-prefix*)
(push (pathname (concatenate 'string maxima::*maxima-prefix* "/share/locale/"))
intl::*locale-directories*))
(setf (values input-stream batch-flag)
(maxima::process-maxima-args input-stream batch-flag))))
)


(defparameter *maxima-package* (find-package :maxima))

(defun maxima::intern-invert-case (string)
(intern (maxima::maybe-invert-string-case string) *maxima-package*))
-------------------------------------------------------------

The remainder of the code is so far unchanged (by me at least), only the
initialization of Maxima needed to be updated. I hope this helps others who wish
to use the features of Maxima from within their Lisp code.

Best regards,
Knut Gjerden
Richard Fateman
2009-06-15 21:04:19 UTC
Permalink
I think you should check on the responses to Bruno Daniel's original
post, which suggest that
the features supplied by his code were already in Maxima, in the form of
translate() and compile()
commands, along with mode_declare.

Perhaps you should try whatever specific examples you have, using these
facilities. If you encounter
a problem in which symbolic or numeric computation is needed and cannot be
supplied by them, but is solved by Bruno Daniel's code, that would be of
some interest.

RJF
Knut Gjerden
2009-06-18 12:53:36 UTC
Permalink
Dear Mr. Fateman,

I have checked these replies, but I do not agree that translate() and compile()
are what I am looking for.

For me, the whole point is to be able to do something like

(usepackage maxima)
(defun some funcfions)
(let ((some variables) (some environment))
(loop
(setf (a variable) (result of some function))
(integrate (some function)
(do something with the function(s))
(return answer))

i.e., to seamlessly use functions from Maxima in my lisp code. I do not want to
do this by starting Maxima and typing in my functions and "manually" transfer
these back into lisp, or by essentially writing a lisp script in Maxima. Yes of
course I could do this (just start Maxima and enter to_lisp();) , but I whish to
work from lisp, not Maxima. This is just a preference, of course, but I believe
that others may share my point of view and therefore I should share this code.

Best regards,
Knut
Richard Fateman
2009-06-18 14:03:25 UTC
Permalink
I pointed out to Knut that an alternative way setting up his desired
environment is to use the ordinary command-line maxima, and have in his
maxima-init.mac file the line
to_lisp();
This will open up a window to load, execute etc programs in lisp, ,the
same as his setup.
RJF

Loading...