Re: newline conventions



> * Kent M Pitman <cvgzna@xxxxxxxxxxx> [2005-08-30 12:52:43 +0000]:
>
> Many people like me who come from LispM days always protect our
> output by doing
> (format t "~&...~%")
> to say "make sure the previous I/O cleaned up, and make sure we don't
> leave ourselves mid-line either."

CLISP offers "elastic newline":
<http://clisp.cons.org/impnotes/stream-dict.html#elastic-newline>:

The function (EXT:ELASTIC-NEWLINE [stream]) is like FRESH-LINE but the
other way around: It outputs a conditional newline on stream, which is
canceled if the next output on stream happens to be a newline. More
precisely, (EXT:ELASTIC-NEWLINE [stream]) causes a newline to be output
right before the next character is written on stream, if this character
is not a newline. The newline is also output if the next operation on
the stream is FRESH-LINE, FINISH-OUTPUT, FORCE-OUTPUT or CLOSE.

The functionality of EXT:ELASTIC-NEWLINE is also available through the
FORMAT directive ~..

A technique for avoiding unnecessary blank lines in output is to begin
each chunk of output with a call to FRESH-LINE and to terminate it with
a call to EXT:ELASTIC-NEWLINE.

See
<http://cvs.sourceforge.net/viewcvs.py/*checkout*/clisp/clisp/doc/Newline-Convention.txt>
for rationale.

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.palestinefacts.org/> <http://truepeace.org> <http://www.memri.org/>
<http://ffii.org/> <http://www.dhimmi.com/> <http://www.savegushkatif.org>
If it has syntax, it isn't user friendly.
.



Relevant Pages

  • Re: cannot use char and integer in the same program
    ... first scanf is going to read the characters "123" and the newline (from ... it back onto the stream, ... thing) so it will read the newline (the next character in the stream) ... The third scanf call reads the character 'a' off ...
    (comp.lang.c)
  • Re: peek at stdin, flush stdin
    ... at least one character other than newline following the one ... other than newline, ... scanning an input stream containing "y\n" puts the ... (Here scanf() ...
    (comp.lang.c)
  • Re: CLISP always outputs a newline when it exits
    ... (And always did expect a newline on all lines, ... In fact, in ANSI C, the behavior is undefined if the last character ... Whether the last line requires a terminating new-line character is ... Data read in from a text stream will necessarily compare equal to ...
    (comp.lang.lisp)
  • Re: CLISP always outputs a newline when it exits
    ... (And always did expect a newline on all lines, ... In fact, in ANSI C, the behavior is undefined if the last character ... the unsatisified requirement causes undefined behavior. ... Data read in from a text stream will necessarily compare equal to ...
    (comp.lang.lisp)
  • Re: newbie EOF question
    ... >portable code must terminate any output to a text stream with a newline. ... (in order to keep the input on the same line as the prompt) ...
    (comp.lang.c)