重复调用格式忽略~t选项

joh*_*ers 1 lisp common-lisp

我有这个:

(defun promptread (prompt) 
  (format *query-io* "~10t~a:" prompt)
  (force-output *query-io*)
  (read-line *query-io*))
(defun prompt-cd ()
    (make-cd
     (promptread "Artist")
     (promptread "Album")
     (promptread "Rating")
     (promptread "Like [y/n]")))
Run Code Online (Sandbox Code Playgroud)

它有效,但格式~10t只会影响对promptread内部的第一次调用make-cd; 其他人没有这个填充物左对齐.

为什么会这样?

REPL:

CL-USER> (addcds)
          Artist:Dixie
 Album:Funny
 Rating:22
Run Code Online (Sandbox Code Playgroud)

第一个promptread是缩进的,因为formatwith ~10t而不是其他,它们使用相同的确切format调用.

Ter*_* D. 5

问题是在force-output和之后readline,不知道光标format位于0处.因此绝对制表将失败.如果你用格式字符串启动~&,你会看到这个,因为无论如何都会输出一个额外的换行符.

要解决此问题,请使用@修饰符获取相对列表:

(format *query-io* "~10@t~a:" prompt)
Run Code Online (Sandbox Code Playgroud)