prompt-work (was [Maxima-commits] [git] Maxima CAS branch, master, updated. branch-5_31-base-183-gf44d669)



>   From: Rupert Swarbrick <rswarbrick at gmail.com>
>   Date: Thu, 12 Dec 2013 00:34:45 +0000
>
>   Robert Dodier <robert.dodier at gmail.com> writes:
>   > Yeah -- I'm planning to make a release branch around Dec 15. How about
>   > if the commits related to prompt stuff are moved onto a branch? Seems
>   > like that should be possible with Git, but I don't know for sure.
>
>   Assuming I got the revert and cherry-pick incantations right
>   (eventually), I've just reverted parts 2 and 3 of my patch set under
>   discussion. I've also pushed a "prompt-work" branch to Sourceforge which
>   currently has my original patch set. I hope that makes sense.

Rupert, thanks for doing this. And thanks for centralizing the use of
the prompt decorations into format-prompt.

I would like to reach some sort of agreement on the remainder of these
works. Based on my reading of 
http://www.math.utexas.edu/pipermail/maxima/2013/034687.html
we are close.


Let me start by explaining in more detail the patch I sent:

-$set_alt_display provides a simple, functional way to set/reset the
*alt-display1/2d* hooks from the Maxima repl.

-define_alt_display is a macro that provides some translation from
Maxima variable names to Lisp ones, to make writing a hook in Maxima
easier. It also encases the Maxima code in some error handling shell.

-$set_prompt provides a simple, functional way to control the input
prompt decorations from the Maxima repl without exposing the *prompt-*
variables directly.

The 1st+2nd functions provide a means to manage and write alt-display
hooks as Maxima code [1]. **These answer a real need**: we have had a few
requests in the last year where users wanted to massage Maxima's
output, each of which were solved via alt-display hooks.

In addition, as I showed in the commit notes, one can dynamically
update the prompt pre/suffix with an alt-display hook, so the code
provides a means to achieve the effects of prompt-notes, too.  Indeed,
prompt-notes can be effected in Maxima on top of these two functions.

One last point about my patch: alt-display is meant to be a contrib
package (see the patch I sent). Contrib packages are experimental
and/or less stable than src code. 

Finally, concerning safety and a hook in format-prompt.

I am not really convinced a separate hook in format-prompt is needed,
given set_alt_display/define_alt_display, but...

Maxima generally provides little by way of safety. If you want to bork
your session, try

f([x]):=f(x,x);
f(1);

gcl segfaults on a second call after recovering from the first; sbcl
borks on one call. I imagine we could "fix" that by policing arglist
length, but Maxima does not.

In my experience working on the format-prompt hook, it was useful to
run swank+slime+Maxima. That let me do things that a try-catch wrapper
can't. (Ever wonder why Lisp has no try-catch macro?
http://gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html)

If you *absolutely* must have safety beyond that provided by those
tools, then how about, in format-prompt,


(cond ($format_prompt
       (handler-bind ((error (lambda(msg) (setq $format_prompt nil) (merror ....)))))
         (mfuncall $format_prompt ....))
      (t
        ....)))


You are right, if we expose this hook, then it makes sense to expose
the standard input prompt as a Maxima function returning a string. The
default clause can then invoke it.

(I use a Maxima variable name because it is intended that format_prompt
be accessible from the Maxima repl.)

Leo


[1] - you claim otherwise in
http://www.math.utexas.edu/pipermail/maxima/2013/034687.html, but look
at the examples I showed and you'll see this is mistaken.