Ticket #7377: trac_7377-better-ask-error.patch

File trac_7377-better-ask-error.patch, 2.1 KB (added by nbruin, 11 years ago)

improved formatting of error message when maxima asks a question

  • sage/interfaces/maxima_lib.py

    # HG changeset patch
    # User Nils Bruin <nbruin@sfu.ca>
    # Date 1297666400 28800
    # Node ID e173f4a68672f4b28a2435a5e26c401e3b92b065
    # Parent  2aa53d20ef6082fac0ec6218b29a469ea7cf13ae
    Better formatting of error messages thrown when Maxima throws an error
    diff -r 2aa53d20ef60 -r e173f4a68672 sage/interfaces/maxima_lib.py
    a b  
    490490ecl_eval("(defun add-lineinfo (x) x)")
    491 ecl_eval("""(defun retrieve (msg flag &aux (print? nil))(error (concatenate 'string "Maxima asks:" (meval (list '($string) msg)))))""")
     491#the following is a direct adaption of the definition of "retrieve" in the Maxima file
     492#macsys.lisp. This routine is normally responsible for displaying a question and
     493#returning the answer. We change it to throw an error in which the text of the question
     494#is included. We do this by running exactly the same code as in the original definition
     495#of "retrieve", but with *standard-output* redirected to a string.
     497(defun retrieve (msg flag &aux (print? nil))
     498  (declare (special msg flag print?))
     499  (or (eq flag 'noprint) (setq print? t))
     500  (error (concatenate 'string "Maxima asks:" (with-output-to-string (*standard-output*)
     501      (terpri)
     502      (cond ((not print?)
     503             (setq print? t)
     504             (princ *prompt-prefix*)
     505             (princ *prompt-suffix*))
     506            ((null msg)
     507             (princ *prompt-prefix*)
     508             (princ *prompt-suffix*))
     509            ((atom msg)
     510             (format t "~a~a~a" *prompt-prefix* msg *prompt-suffix*)
     511             (mterpri))
     512            ((eq flag t)
     513             (princ *prompt-prefix*)
     514             (mapc #'princ (cdr msg))
     515             (princ *prompt-suffix*)
     516             (mterpri))
     517            (t
     518             (princ *prompt-prefix*)
     519             (displa msg)
     520             (princ *prompt-suffix*)
     521             (mterpri)))))))
    492524ecl_eval('(defparameter *dev-null* (make-two-way-stream (make-concatenated-stream) (make-broadcast-stream)))')
    493525ecl_eval('(defun principal nil (error "Divergent Integral"))')