Ticket #7377: errorcatching.patch

File errorcatching.patch, 2.4 KB (added by nbruin, 8 years ago)

improve maxima-eval error reporting

  • sage/interfaces/maxima_lib.py

    # HG changeset patch
    # User Nils Bruin <nbruin@sfu.ca>
    # Date 1296372056 28800
    # Node ID b126bfaae82fe22ba5f781d4525abd6a03cecce9
    # Parent  b5c8d7135782fc7183c5815b9311e573953da8bd
    [mq]: errorcatching.patch
    
    diff -r b5c8d7135782 -r b126bfaae82f sage/interfaces/maxima_lib.py
    a b  
    492492ecl_eval('(defparameter *dev-null* (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream)))')
    493493ecl_eval('(defun principal nil (error "Divergent Integral"))')
    494494
     495ecl_eval("(setf $errormsg nil)")
     496
    495497maxima_eval=ecl_eval("""
    496     (defun maxima-eval( form )
    497         (let ((result (catch 'macsyma-quit (cons 'maxima_eval (meval form)))))
    498             ;(princ (list "result=" result))
    499             ;(terpri)
    500             ;(princ (list "$error=" $error))
    501             ;(terpri)
    502             (cond
    503                 ((and (consp result) (eq (car result) 'maxima_eval)) (cdr result))
    504                 ((eq result 'maxima-error) (error (cadr $error)))
    505                 (t (error (concatenate 'string "Maxima condition. result:" (princ-to-string result) "$error:" (princ-to-string $error))))
    506             )
     498(defun maxima-eval( form )
     499    (let ((result (catch 'macsyma-quit (cons 'maxima_eval (meval form)))))
     500        (princ (list "result=" result))
     501        (terpri)
     502        (princ (list "$error=" $error))
     503        (terpri)
     504        (cond
     505            ((and (consp result) (eq (car result) 'maxima_eval)) (cdr result))
     506            ((eq result 'maxima-error)
     507                (let ((the-jig (process-error-argl (cddr $error))))
     508                    (mapc #'set (car the-jig) (cadr the-jig))
     509                    (error
     510                       (with-output-to-string (stream)
     511                           (apply #'mformat stream (cadr $error) (caddr the-jig))))
     512                ))
     513            (t
     514                (let ((the-jig (process-error-argl (cddr $error))))
     515                    (mapc #'set (car the-jig) (cadr the-jig))
     516                    (error (concatenate 'string "Maxima condition. result:" (princ-to-string result) "$error:"
     517                       (with-output-to-string (stream)
     518                           (apply #'mformat stream (cadr $error) (caddr the-jig)))))
     519                ))
    507520        )
    508521    )
     522)
    509523""")
    510524
    511525#ecl_eval('(defun ask-evod (x even-odd)(error "Maxima asks a question"))')