Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How does `~&' know the ostream is already at the beginning of line?

CL-USER> (progn
           (format t "abc~%")
           (format t "~&abc"))
abc
abc
NIL
CL-USER> 

My guess is: a ostream descriptor always stores the latest char sent to it.
Say, after ostream receiving an #\a,FORMAT can determine that the ostream is not at the beginning because the latest char sent to it is #\a.

But I’m not sure that’s really the case.

Any help is appreciated.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

~& just calls fresh-line, so the question is in fact how does fresh-line know this, and the answer is

  • it is not required to know it at all: see TERPRI, FRESH-LINE;
  • and how it knows it is entirely up to the implementation.

If you look at various implementations for which source is available you will probably find various ways they do this. For instance SBCL has an fd-stream object (in src/code/fd-stream.lisp) which keeps track of the output-column. But how implementations do this, and whether they do it at all, is up to them.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading