如何使用lisp格式函数用零填充参数?

时间:2022-09-02 23:21:40

I am playing around with lisp's format function, but I have hit a snag because although I can get it to write the list of numbers aligned nicely, I can't seem to get it to zero pad it:

我正在玩lisp的格式化功能,但是我遇到了麻烦,因为虽然我可以让它编写好的数字列表,但我似乎无法将其填充为零:

(defun inc (a) (+ 1 a))
(dotimes (i 10)
  (format t "~3@:D ~:*~R~%" (inc i)))

This produces the following output:

这会产生以下输出:

+1: one
+2: two
+3: three
+4: four
+5: five
+6: six
+7: seven
+8: eight
+9: nine
+10: ten

Does anybody know how to get it to be zero-padded?

有人知道如何让它成为零填充吗?

1 个解决方案

#1


Example lifted from the PCL chapter on FORMAT:

从FORML的PCL章节中解除的例子:

(format nil "~12d" 1000000)    ==> "     1000000"
(format nil "~12,'0d" 1000000) ==> "000001000000"

#1


Example lifted from the PCL chapter on FORMAT:

从FORML的PCL章节中解除的例子:

(format nil "~12d" 1000000)    ==> "     1000000"
(format nil "~12,'0d" 1000000) ==> "000001000000"