[Maxima-commits] [git] Maxima CAS branch, master, updated. branch-5_31-base-183-gf44d669
Subject: [Maxima-commits] [git] Maxima CAS branch, master, updated. branch-5_31-base-183-gf44d669
From: Leo Butler
Date: Wed, 11 Dec 2013 19:01:30 GMT
> From: Robert Dodier <robert.dodier at gmail.com>
> Date: Fri, 6 Dec 2013 21:27:36 +0000
>
> On 2013-12-05, Rupert Swarbrick <rswarbrick at gmail.com> wrote:
>
> > I didn't realise the commits were potentially controversial - I would
> > have asked on the mailing list first if I had.
>
> For the record, I don't believe it's necessary to get support for all
> changes before committing something. We can use the revision control
> system to revert changes after the fact. I don't mean to suggest that
> developers can ignore the opinions of others, only that an occasional
> reversion is an acceptable price to pay for getting more work done.
>
> > I intentionally didn't try to use *prompt-prefix* and *prompt-suffix*
> > here because I know that they are designed for front-ends to "tag" their
> > prompts easily. Since they are just strings, I couldn't think of a way
> > to add a note after the prompt without potentially clobbering them. But
> > maybe I missed something?
>
> I dunno, I'm not convinced the prompt note system is useful enough.
> I can see that being able to rework the prompts is going to be useful
> for people writing user interfaces -- agreed on that point. But isn't
> it enough for that purpose to concentrate the prompt formatting into
> a single function (as in the previous commit, which, as I said, is OK
> by me) which can then be replaced easily enough? We could even make the
> prompt formatter a Maxima function so that it can be replaced by Maxima
> code.
Attached is a patch that includes Robert's suggestion. I change
format-prompt so that it mfuncall-s $format_prompt if this is non-nil.
There is also contrib code to manipulate *prompt-suffix*,
*prompt-prefix*, and *alt-display1/2d* from the Maxima repl. Rupert's
notes system can easily be implemented in Maxima code on top of
this. The commit log shows some examples.
Leo
===File ~/git.diff==========================================
diff --git a/doc/info/Command.texi b/doc/info/Command.texi
index 24eac12..fb0afcf 100644
--- a/doc/info/Command.texi
+++ b/doc/info/Command.texi
@@ -728,28 +728,6 @@ Default value: @code{_}
@end defvr
@c -----------------------------------------------------------------------------
- at deffn {Function} prompt_prepend_note (note)
-
-Add a note that is displayed after every input prompt. This note must
-either be a string or it should be something that can be called as a
-function. In the latter case, the function should return either a
-string or a number (for technical implementation reasons, arbitrary
-expressions might not be printed correctly). If the function call
-raises an error then the note is removed from the list to be
-displayed from then on.
-
-There can be more than one note displayed after a prompt, and this
-adds the given note to the left hand end of the list. To remove a note
-from the list, use @mref{prompt_remove_note}.
- at end deffn
-
- at deffn {Function} prompt_remove_note (note)
-
-Remove a note from the list of objects to display after a prompt. See
- at mref{prompt_prepend_note} for how to add one.
- at end deffn
-
- at c -----------------------------------------------------------------------------
@anchor{quit}
@deffn {Function} quit ()
diff --git a/share/contrib/alt-display/alt-display.lisp b/share/contrib/alt-display/alt-display.lisp
new file mode 100644
index 0000000..80a9ccb
--- /dev/null
+++ b/share/contrib/alt-display/alt-display.lisp
@@ -0,0 +1,43 @@
+;; -*- mode: lisp -*-
+;; Copyright Leo Butler (l_butler at users.sourceforge.net) 2013
+;; Released under the terms of GPLv2+
+
+(defun $set_prompt (type value &rest args)
+ (declare (special *prompt-prefix* *prompt-suffix*))
+ (assert (and (symbolp type) (or (member type '($s $su $suf $suff $suffi $suffix))
+ (member type '($p $pr $pre $pref $prefi $prefix)))
+ (or (stringp value) (null value)))
+ (type value)
+ "set_prompt(type, value): type must be either 'prefix or 'suffix, value must be a string or false.~%type=~a, value=~a" type value)
+ (ecase type
+ (($p $pr $pre $pref $prefi $prefix) (setq *prompt-prefix* (or value "")))
+ (($s $su $suf $suff $suffi $suffix) (setq *prompt-suffix* (or value "")))
+ )
+ (if args (apply '$set_prompt args))
+ '$done)
+
+(defun $set_alt_display (type f &rest args)
+ (assert (and (member type '(1 2))
+ t)
+ (type f)
+ "set_alt_display(type,f): type must equal 1 or 2, f must be a function.")
+ (let ((alt-display (ecase type
+ (1 '*alt-display1d*)
+ (2 '*alt-display2d*))))
+ (flet ((reset-display (&optional no-warn)
+ (unless no-warn (warn "Resetting display."))
+ (set alt-display nil)))
+ (cond ((null f) (reset-display t))
+ (t
+ (handler-case
+ (set alt-display
+ (coerce (lambda(form)
+ (handler-case (mfuncall f form)
+ (error () "Error in ~a. ~a" alt-display (reset-display))))
+ 'function))
+ (error (msg) "In ~a, an error has occurred, resetting to ~a.~%~a" alt-display (reset-display) msg))))))
+ (if args (apply #'$set_alt_display args))
+ '$done)
+
+
+; end of alt-display.lisp
diff --git a/share/contrib/alt-display/alt-display.mac b/share/contrib/alt-display/alt-display.mac
new file mode 100644
index 0000000..ee259b5
--- /dev/null
+++ b/share/contrib/alt-display/alt-display.mac
@@ -0,0 +1,22 @@
+/* -*- Mode: maxima; Package: MAXIMA -*- */
+/*
+;; Copyright Leo Butler (l_butler at users.sourceforge.net) 2013
+;; Released under the terms of GPLv2+
+*/
+
+load("alt-display.lisp");
+
+define_alt_display(f,body) ::= buildq(
+ [f:f,
+ body:psubst([
+ alt_display1d='?\*alt\-display1d\*,
+ alt_display2d='?\*alt\-display2d\*,
+ prompt_prefix='?\*prompt\-prefix\*,
+ prompt_suffix='?\*prompt\-suffix\*,
+ displa='?displa
+ ],
+ body)],
+ f := block([simp:false], body));
+
+
+/* end of alt-display.mac */
diff --git a/src/macsys.lisp b/src/macsys.lisp
index 7e64201..12dec8c 100644
--- a/src/macsys.lisp
+++ b/src/macsys.lisp
@@ -22,10 +22,6 @@
(defmvar $prompt '_
"Prompt symbol of the demo function, playback, and the Maxima break loop.")
-;; This variable is bound to T when we are displaying one of the "(%i3)"-style
-;; prompts, and enables the printing of notes.
-(defvar *displaying-input-prompt* nil)
-
;; A prefix and suffix that are wrapped around every prompt that Maxima
;; emits. This is designed for use with text-based interfaces that drive Maxima
;; through standard input and output and need to decorate prompts to make the
@@ -33,71 +29,22 @@
;; doc/implementation/external-interface.txt.
(defvar *prompt-prefix* "")
(defvar *prompt-suffix* "")
-
-;; This should be a list of notes to append to a prompt. Each element can either
-;; be a string or something that is funcallable using MFUNCALL. It should take
-;; no arguments and return an object that will be PRINC'ed to display it.
-;;
-;; Add and remove notes with $PROMPT_PREPEND_NOTE and
-;; $PROMPT_REMOVE_NOTE. Unlike *PROMPT-PREFIX* and *PROMPT-SUFFIX* these notes
-;; are intended for human consumption, rather than to aid machine interfaces.
-(defvar *prompt-notes* nil)
-
-(defun $prompt_remove_note (note)
- (setf *prompt-notes* (delete note *prompt-notes* :test 'equal))
- (values))
-
-(defun $prompt_prepend_note (note)
- ($prompt_remove_note note)
- (push note *prompt-notes*)
- (values))
-
-;; Return a string formed of the notes in *prompt-notes*
-(defun prompt-notes ()
- (labels ((note-funcall (note)
- ;; This code tries to call MFUNCALL on a note, but will remove any
- ;; note that doesn't work. We have to do this to avoid an infinite
- ;; loop when someone does something like "prompt_prepend_note(1);"
- (let ((failed t))
- (unwind-protect
- (prog1 (mfuncall note)
- (setq failed nil))
- (when failed
- (setf *prompt-notes*
- (delete note *prompt-notes*))))))
- (eval-note (note)
- (if (stringp note) note (note-funcall note))))
-
- (let ((evalled (delete nil (mapcar #'eval-note *prompt-notes*))))
- (cond
- ((null evalled) "")
- (t
- (with-output-to-string (stream)
- (princ "[" stream)
- (princ (first evalled) stream)
- (loop
- for note in (rest evalled)
- do (princ "; " stream)
- do (princ note stream))
- (princ "] " stream)))))))
+(defvar $format_prompt nil "If NIL, use format-prompt to print input prompt; if a function, use it to print input prompt.")
(defvar *general-display-prefix* "")
(defun format-prompt (destination control-string &rest arguments)
"Like AFORMAT, but add the prefix and suffix configured for a prompt. This
function deals correctly with the ~M control character, but only when
-DESTINATION is an actual stream (rather than nil for a string).
-
-This function also obeys the special variable *DISPLAYING-INPUT-PROMPT*. If that
-is true, it also shows prompt notes, as set with prompt_prepend_note()."
- (let ((*print-circle* nil))
- (concatenate 'string
- *prompt-prefix*
- (apply 'aformat destination control-string arguments)
- (if *displaying-input-prompt*
- (prompt-notes)
- "")
- *prompt-suffix*)))
+DESTINATION is an actual stream (rather than nil for a string)."
+ (cond ($format_prompt
+ (mfuncall $format_prompt destination control-string arguments))
+ (t
+ (let ((*print-circle* nil))
+ (concatenate 'string
+ *prompt-prefix*
+ (apply 'aformat destination control-string arguments)
+ *prompt-suffix*)))))
;; "When time began" (or at least the start of version control history),
;; the following comment was made at this point:
@@ -112,12 +59,11 @@ is true, it also shows prompt notes, as set with prompt_prepend_note()."
;; don't deal correctly with ~M plus a string output stream.
(defun main-prompt ()
(declare (special *display-labels-p*))
- (let ((*displaying-input-prompt* t))
- (if *display-labels-p*
- (format-prompt nil "(~A~A) "
- (print-invert-case (stripdollar $inchar))
- $linenum)
- "")))
+ (if *display-labels-p*
+ (format-prompt nil "(~A~A) "
+ (print-invert-case (stripdollar $inchar))
+ $linenum)
+ ""))
(defun break-prompt ()
(format-prompt nil "~A"
diff --git a/src/suprv1.lisp b/src/suprv1.lisp
index 1d07a03..b08d495 100644
--- a/src/suprv1.lisp
+++ b/src/suprv1.lisp
@@ -337,8 +337,7 @@
checkfactors nil greatorder nil lessorder nil $gensumnum 0
$weightlevels '((mlist)) *ratweights nil $ratweights
'((mlist simp))
- tellratlist nil $dontfactor '((mlist)) $setcheck nil
- *prompt-notes* nil)
+ tellratlist nil $dontfactor '((mlist)) $setcheck nil)
(killallcontexts))
((setq z (assoc x '(($inlabels . $inchar) ($outlabels . $outchar) ($linelabels . $linechar)) :test #'eq))
(mapc #'(lambda (y) (remvalue y '$kill))
============================================================
===File ~/git.log===========================================
commit 117a2f3a6601e30f3d3766cd401f976467d8eade
Author: Leo Butler <l_butler at users.sourceforge.net>
Date: Wed Dec 11 12:25:10 2013 -0500
contrib code to provide easy-to-use access to the $format_prompt hook
provided in the previous commit.
-alt-display.lisp provides:
$set_prompt => to easily set/reset *prompt-prefix*/*prompt-suffix* from Maxima repl
$set_alt_display => to bind *alt-display1/2d* to an mfuncall-able function, encased in some minimal error-protection shell
-alt-display.mac provides:
define_alt_display => macro to define a Maxima function that can be used as an argument to set_alt_display; the macro does some basic psubstition of Maxima variable names for the Lisp variable names.
Examples:
Maxima branch_5_31_base_199_g1f8e92c_dirty http://maxima.sourceforge.net
using Lisp GNU Common Lisp (GCL) GCL 2.6.10 (a.k.a. GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) load("alt-display.mac")$
(%i2) set_prompt('prefix,"<== ",'suffix,"==> ");
(%o2) done
<== (%i3) ==> set_prompt('s,false);
(%o3) done
<== (%i4) define_alt_display(f(x), block([alt_display1d:false],(prompt_prefix:printf(false,"ibase=~d~%",ibase), displa(x))));
(%o4) f(x):=block([simp:false],
block([?\*alt\-display1d\*:false],
(?\*prompt\-prefix\*:printf(false,"ibase=~d~%",ibase),
?displa(x))))
<== (%i5) set_alt_display(1,'f);
(%o5) done
ibase=10
(%i6) ibase:5;
(%o6) 5
ibase=5
(%i7) 34;
(%o7) 19
ibase=5
(%i8) ibase:7.;
(%o8) 7
ibase=7
(%i9) quit();
commit f07ab8f241199d8d20e70ffd17c6cae470dc173f
Author: Leo Butler <l_butler at users.sourceforge.net>
Date: Wed Dec 11 11:42:32 2013 -0500
Removes the prompt-notes machinery (commit fdcd9389). Replaces this
with a mfuncall-able variable $format_prompt, which, when non-nil is
mfuncall-ed instead of format-prompt. This permits an arbitray hook to
replace the default format-prompt.
See the discussion following http://www.math.utexas.edu/pipermail/maxima/2013/034659.html
============================================================