且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么在clojure中使用'print'打印的字符串在我使用println后只出现在我的控制台中?

更新时间:2023-11-14 12:28:04

更仔细地查看Clojure源代码 println 打印。区别在于 println 调用 prn 并打印调用 pr 。在 prn 函数 换行符。然后它检查 flush-on-new-line ,如果是true,它显式地调用 flush 。因此,在字符串中调用 print 和任何数字的换行符(\\\
)不会刷新到输出流,您必须调用 newline ,或直接调用 flush

After looking more closely at the Clojure source code for println and print. The difference is that println calls prn and print calls pr. In the prn the function newline is called. It then checks for flush-on-new-line and if it is true it explicitly calls flush. Therefore calling print with any number of newlines ("\n") in the string will not flush to the output stream, you must either call newline, or call flush directly.