Repeatable issue one by one in Common Lisp format

In my format ~VT tabs behave differently depending on whether the newline ~% at the beginning or end of the lines, and I would like to know why. The difference is that when a new line is at the end of lines, the first instance seems to have extra tab-only space. The following examples illustrate. The only difference in the examples is in the format control line: it "~%~A~VT= ~A" in the first example and "~A~VT= ~A~%" in the second.

EXAMPLE 1: new line at the beginning of output lines

 (let ((sb (make-array 0 :element-type 'character :adjustable t :fill-pointer 0))) (mapcar (lambda (line) (format sb "~%~A~VT= ~A" line 10 42)) '(a abcd asdf foobar g november)) sb) " A = 42 ABCD = 42 ASDF = 42 FOOBAR = 42 G = 42 NOVEMBER = 42" 

The behavior here is as expected.

EXAMPLE 2: new line at the ends of output lines

In this example, it should be noted that the first line,

 A = 42 

has one more space in it than the corresponding line from example 1:

 A = 42 

It's a little hard to see because of the leading double quote, and so I cut it off: to help you see them better. This is repeatable on much larger examples and is MVE devoid of a much larger program.

 (let ((sb (make-array 0 :element-type 'character :adjustable t :fill-pointer 0))) (mapcar (lambda (line) (format sb "~A~VT= ~A~%" line 10 42)) '(a abcd asdf foobar g november)) sb) "A = 42 ABCD = 42 ASDF = 42 FOOBAR = 42 G = 42 NOVEMBER = 42 " 

The question with the big picture "why?" I use SBCL 1.3.1 on a Mac and have not tried it in other implementations. It may be a mistake, but it seems more plausible that it was intended for behavior, but I don’t understand what it could be for achievement, and I could not find an explanation in the format documentation.

+5
source share
1 answer

I think this is a mistake. I can also play it on Linux using SBCL 1.3.1.

~T may require a heuristic (which may fail) to determine the current column in some cases, but I think the beginning of the line should be considered column 0.

At least on my computer this does not happen when a simple with-output-to-string :

 (with-output-to-string (s) (mapcar (lambda (line) (format s "~A~VT= ~A~%" line 10 42)) '(a abcd asdf foobar g november))) 

This happens, however, when you pass the previously created string to with-output-to-string :

 (let ((sb (make-array 0 :element-type 'character :adjustable t :fill-pointer 0))) (with-output-to-string (s sb) (mapcar (lambda (line) (format s "~A~VT= ~A~%" line 10 42)) '(a abcd asdf foobar g november)) sb)) 
+4
source

Source: https://habr.com/ru/post/1240885/


All Articles