evaluate Maxima string from lisp command line...



> ...how to take a string in regular maxima input format,
> and feed it to Maxima on the lisp level

In other words, you want to parse a string as Macsyma language.  The
macsyma-read-string function is supposed to do this, but doesn't work in
5.9.0/GCL.  It also has no error handling.  I have rewritten it from
scratch.  Give it a whirl.

  (meval (macsyma-read-string "diff(x^2,x)"))
    => ((MTIMES SIMP) 2 |$x|)

;;; Copyright 2004 by Stavros Macrakis
;;; Licensed under your choice of the GPL or the modified BSD license

;;; Parse a string as a Maxima expression
;;; Return the parsed form
;;; If there's an error, it returns the symbol parse-error; the
;;; second return value is then the error string.

;;; Usage examples:
;;;
;;; (macsyma-read-string "1/+3*x") =>
;;;   ((MQUOTIENT) 1 ((MPLUS) ((MTIMES) 3 |$x|)))
;;;   NIL
;;;
;;; Note that this is simply parsed -- no simplification.
;;; The simplified form is 
;;; ((MTIMES SIMP) ((RAT SIMP) 1 3) ((MEXPT SIMP) |$x| -1))
;;;
;;; (macsyma-read-string "1.2.3") =>
;;;   NIL
;;;   "Incorrect syntax: 0.29999999999999999 is not an infix operator"

(defun macsyma-read-string (str)
  (with-input-from-string
   (stream (concatenate 'string str "$"))
   (let* ((*standard-input* stream)
          (*standard-output* (make-string-output-stream))
            ;; catches error strings
          (expr
           (catch 'macsyma-quit
             (list (caddr (mread stream)))))
          (error-string (get-output-stream-string *standard-output*)))
     (values
      (if (atom expr) 'parse-error (car expr))
      (cond ((not (equal error-string "")) error-string)
            ((tyi stream) "Excess characters in input string")
            ((not (listp expr)) "Unknown read error")
            (t nil))))))