Clojure printing functions: pr vs print

时光毁灭记忆、已成空白 提交于 2020-08-22 03:01:46

问题


What is the difference between pr/prn and print/println?

When would one be used over the other?


回答1:


They differ in the following ways.

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

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

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

For example:

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

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


来源:https://stackoverflow.com/questions/21136766/clojure-printing-functions-pr-vs-print

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!