Clojure printing functions: pr vs print

后端 未结 1 1564
执笔经年
执笔经年 2021-02-11 20:49

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

When would one be used over the other?

相关标签:
1条回答
  • 2021-02-11 21:36

    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" \!
    
    0 讨论(0)
提交回复
热议问题