Common Lisp格式的可重复的一次性发行 [英] Repeatable off-by-one issue in Common Lisp's format

查看:94
本文介绍了Common Lisp格式的可重复的一次性发行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有格式的选项卡〜VT 表现不同,具体取决于换行符 〜%在行的开头或结尾,我想知道为什么。区别在于,当换行符位于行尾时,制表位的仅第一个实例中似乎有多余的空间。以下示例说明。示例中的唯一区别在于格式控制字符串:第一个示例中为〜%〜A〜VT =〜A 第二个是〜A〜VT =〜A〜%

I have format's tabs ~VT behaving differently depending on whether the newline ~% is at the beginning or the end of lines, and I wanted to know why. The difference is that when the newline is at the end of lines, there seems to be an extra space in the first instance only of the tab stop. The following examples illustrate. The only difference in the examples is in the format-control string: it's "~%~A~VT= ~A" in the first example and "~A~VT= ~A~%" in the second.

(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 thing to notice in this example is that the first line,

A         = 42

其中的空间比示例1中对应的行多一个空间: / p>

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

A        = 42

有点麻烦d会因为双引号引起来而看到它,这就是为什么我将其删除:帮助您更好地看到它们。
这在更大的示例中可以重复,并且是从更大的程序中剥离的MVE。

It's a little hard to see because of the leading double-quote, and that's why I snipped this out: to help you see them better. This is repeatable on much bigger examples and is an MVE stripped out 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
"

最大的问题是为什么?我在Mac上使用的是SBCL 1.3.1,还没有在其他实现上尝试过。它可能是一个错误,但似乎可以预期是它的行为,但我不知道它可以达到的目的,而且我无法在格式的文档中找到解释。

The big-picture question is "why?" I'm using SBCL 1.3.1 on a Mac and haven't tried it on other implementations. It could be a bug, but it seems more plausible that it's intended behavior, but I don't understand what it could be intended to accomplish and I haven't been able to find an explanation in format's documentation.

推荐答案

我认为这是一个错误。我也可以使用SBCL 1.3.1在Linux上重现它。

I think that it is a bug. I can also reproduce it on Linux with SBCL 1.3.1.

〜T 可能需要试探法(可能会失败) ),以在某些情况下确定当前列,但我猜该字符串的开头应视为列0。

~T may need heuristics (that can fail) to determine the current column in some cases, but I guess the start of the string should be considered column 0.

至少在我的计算机上,似乎没有发生当使用带有输出字符串的简单 时:

At least on my computer, it seems not to occur when a simple with-output-to-string is used:

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

但是,当您给制成的字符串转换为,带有输出到字符串

It does occur, however, when you give the pre-made 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))

这篇关于Common Lisp格式的可重复的一次性发行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆