Clojure打印功能:PR vs打印 [英] Clojure printing functions: pr vs print

查看:66
本文介绍了Clojure打印功能:PR vs打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pr / prn print / println

何时将一个用于另一个?

When would one be used over the other?

推荐答案

它们在以下方面有所不同。

They differ in the following ways.


  • print / println 产生供人类消费的产出

  • pr / prn 产生可由读者读取的输出

  • print/println produce output intended for human consumption
  • pr/prn produce output that may be read by the reader

因此,在为人类生成输出时使用前一个函数,在为其他Clojure程序生成要消费的输出时使用后者。

So use the former functions when producing output for humans, and the latter for when producing output for other Clojure programs to consume.

在<$ c的情况下$ c> pr / prn ,将用引号引起来,并转义特殊字符。字符也会在字符串之外转义。

In the case of pr/prn, strings will be quoted, and special characters escaped. Characters will also be escaped outside of strings.

例如:

=> (println "Hello\nworld" \!)
Hello
world !

=> (prn "Hello\nworld" \!)
"Hello\nworld" \!

这篇关于Clojure打印功能:PR vs打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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