fresh-line (was: Re: [Maxima] Some main loop fixes)



James Amundson  writes:

> On Tue, 2005-01-18 at 09:24, Richard Fateman wrote:
>> Does this not work when we needed it? ~& or ~1& should do it.
>> "fresh line".
>
> I would like to understand exactly what is going on a little better, but
> Viktor's solution seems to work and life is short.

I'm picking up this thread because I am not quite happy about the
patch (except for the last hunk)

http://sourceforge.net/mailarchive/message.php?msg_id=10586473

IMHO, this approach makes outputting in Maxima a matter of trial and
error across different lisps.  Indeed, a bit of further patch-work was
added to compensate for missing newlines in special situations, but
there are still inconsistencies (e.g., a blank line after `1/0;' in
CMUCL) in the non-socket situation (which is the only one I am
considering here).

I see two solutions (which are not mutually exclusive):

(1) Adopt a strict newline convention, cf. Haible's

    http://cvs.sourceforge.net/viewcvs.py/*checkout*/clisp/clisp/doc/Newline-Convention.txt?rev=1.2

(2) Try to set up the standard streams in a uniform way across
    different lisps.

I have no idea which one is better, but it seemed that trying (2)
would both be more interesting and actually simplify some stuff in
Maxima, so that is what I did.

> The code already had ~&'s and (fresh-line)'s. Somehow the way input
> is read and echoed manages to fool the common lisp "new line only if
> necessary logic". The user's final carriage return creates a new
> line *and* convinces lisp that it is no longer at the beginning of a
> new line. I initially thought I was seeing a bug in the lisp
> implementation, but I determined that CMUCL, GCL, Clisp and SBCL all
> behave the same way, so I doubt it is a simple bug.

With this test function

(defun foo ()
  (finish-output)
  (clear-input)
  (format t "---->")
  (finish-output)
  (read)
  (finish-output)
  (prog1
      (fresh-line)
    (format t "<----")
    (fresh-line)
    (format t "The end")
    (finish-output)))

I find that current versions of CLISP and ECL don't produce a blank
line while GCL, CMUCL and SBCL still do.

I note that CLISP, ECL and GCL set up the standard streams as
described in CLtL2 21.1, that is as synonym streams referring to
*terminal-io*, but CMUCL and SBCL don't (which the Standard allows).

Now, it seems to me that, with strict ANSI CL portability in mind, the
desired behaviour for FRESH-LINE can be expected only if the standard
streams (which are relevant in a given situation) do refer to the same
stream.  Unfortunately, even with such a setup, CMUCL and SBCL
continue to produce those blank lines.  However, a naïve work-around
in terms of a Gray stream wrapper around *terminal-io* seems to work
quite well, see

http://members.inode.at/wjenkner/maxima/tty-io.lisp

This file is written so that it can be be tested without Maxima: Just
(compile and) load it, and in CL-USER do (setup-standard-streams).

This works with CMUCL and SBCL.  I don't know about openmcl and
Allegro, in any case they have Gray streams, so this shouldn't be a
problem.  This would reduce the problem to GCL.

The details of how this could be used with Maxima are discussed in a
separate message with the subject `streams, sockets and the command
line'.

By the way, somebody could please explain why those additional
newlines are considered a major problem for Maxima?

Wolfgang