terpri, princ & co.对比格式
terpri, princ & co. vs format
Common Lisp 的第 9.10 章:符号计算的简要介绍 声称:
The primitive i/o functions TERPRI, PRIN1, PRINC and PRINT were defined in Lisp 1.5 (the ancestor of all modern Lisp systems) and are still found in Common Lisp today. They are included in the Advanced Topics section as a historical note; you can get the same effect with FORMAT.
这意味着您不需要 princ
& co。而且,在现代代码中,您只应该依赖 format
。
这样做有什么缺点吗?分别来说,有没有什么东西是 format
无法实现的,而与其他东西一起工作?
这些函数完全对应于以下 FORMAT
个运算符:
TERPRI
= ~%
FRESH-LINT
= ~&
PRIN1
= ~S
PRINC
= ~A
PRINT
= ~%~S<space>
您也可以使用更现代的 write
。我不是 format
的超级粉丝,因为它的子语言简洁明了,通常是解释性的。请注意,一个好的实现可能能够将格式指令编译为更高效的代码。我主要使用 FORMAT 来缩短复杂的代码,但不会输出普通对象或单回车之类的东西 returns...
Common Lisp 包含三代或更多代文本 I/O API:
- 旧的 s 表达式打印例程
- 专用和通用流IO函数
- 复杂的格式化程序,基于早期的 Fortran and/or Multics IO 格式化程序
- 打印对象的通用函数
- 漂亮的打印机
此外还有半标准的基于 CLOS 的 IO 实现,例如 Gray Streams。
每个都有其用途,none 即将消失...
CL-USER 54 > (let ((label "Social security number")
(colon ": ")
(social-security-number '|7537 DD 459234957324 DE|))
(terpri)
(princ label)
(princ colon)
(princ social-security-number)
(write-char #\newline)
(write-string label)
(write-string colon)
(write social-security-number :escape nil)
(format t "~%~A~A~A" label colon social-security-number)
)
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE
Common Lisp 的第 9.10 章:符号计算的简要介绍 声称:
The primitive i/o functions TERPRI, PRIN1, PRINC and PRINT were defined in Lisp 1.5 (the ancestor of all modern Lisp systems) and are still found in Common Lisp today. They are included in the Advanced Topics section as a historical note; you can get the same effect with FORMAT.
这意味着您不需要 princ
& co。而且,在现代代码中,您只应该依赖 format
。
这样做有什么缺点吗?分别来说,有没有什么东西是 format
无法实现的,而与其他东西一起工作?
这些函数完全对应于以下 FORMAT
个运算符:
TERPRI
=~%
FRESH-LINT
=~&
PRIN1
=~S
PRINC
=~A
PRINT
=~%~S<space>
您也可以使用更现代的 write
。我不是 format
的超级粉丝,因为它的子语言简洁明了,通常是解释性的。请注意,一个好的实现可能能够将格式指令编译为更高效的代码。我主要使用 FORMAT 来缩短复杂的代码,但不会输出普通对象或单回车之类的东西 returns...
Common Lisp 包含三代或更多代文本 I/O API:
- 旧的 s 表达式打印例程
- 专用和通用流IO函数
- 复杂的格式化程序,基于早期的 Fortran and/or Multics IO 格式化程序
- 打印对象的通用函数
- 漂亮的打印机
此外还有半标准的基于 CLOS 的 IO 实现,例如 Gray Streams。
每个都有其用途,none 即将消失...
CL-USER 54 > (let ((label "Social security number")
(colon ": ")
(social-security-number '|7537 DD 459234957324 DE|))
(terpri)
(princ label)
(princ colon)
(princ social-security-number)
(write-char #\newline)
(write-string label)
(write-string colon)
(write social-security-number :escape nil)
(format t "~%~A~A~A" label colon social-security-number)
)
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE