Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

When producing formatted output in Lisp, where should you put the newlines (e.g., before or after the line, FRESH-LINE vs TERPRI, ~& vs ~% in FORMAT)?

0
Posted

When producing formatted output in Lisp, where should you put the newlines (e.g., before or after the line, FRESH-LINE vs TERPRI, ~& vs ~% in FORMAT)?

0

Where possible, it is desirable to write functions that produce output as building blocks. In contrast with other languages, which either conservatively force a newline at various times or require the program to keep track of whether it needs to force a newline, the Lisp I/O system keeps track of whether the most recently printed character was a newline or not. The function FRESH-LINE outputs a newline only if the stream is not already at the beginning of a line. TERPRI forces a newline irrespective of the current state of the stream. These correspond to the ~& and ~% FORMAT directives, respectively. (If the Lisp I/O system can’t determine whether it’s physically at the beginning of a line, it assumes that a newline is needed, just in case.) Thus, if you want formatted output to be on a line of its own, start it with ~& and end it with ~%. (Some people will use a ~& also at the end, but this isn’t necessary, since we know a priori that we’re not at the beginning of a line. The only exc

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123