Why does a line printed using 'print' in clojure only appear on my console after using println?

I have the following code in clojure:

(do
    (println "starting....")
    (sig! a 0)
    (sig! b 0)
    (future
      (Thread/sleep 4000)
      (println "switch 1")
      (sig! a 1)
      (sig! b 0)
      (Thread/sleep 4000)
      (println "switch 2")
      (sig! a 0)
      (sig! b 1)
      (Thread/sleep 4000)
      (println "switch 3")
      (sig! a 1)
      (sig! b 1)) nil))

I have observers who listen to atoms a, b, s and c1 and print out some lines when they change. Use (print (str uid ":" @o "\n")or version of println. Clojure documents say print, and printlnare expected to behave in the same way, except a new line in println, but I do not see it. When the observer uses println, I immediately see the lines. When the observer uses print. I only see the exit when the next one is called println. Below, I have output printlnvs with print. With printI see only the values ​​to the last println.

starting....
switch 1
a:1
s:1
switch 2
a:0
b:1
s:0
s:1
switch 3 

Now with println

starting....
switch 1
a:1

s:1

switch 2
a:0
b:1


s:0

s:1

switch 3
a:1

s:0

c1:1

, , . clojure 1.5. , print , println .

+4
3

Clojure code println print. , println prn pr. prn newline. "flush-on-new-line", , flush. print ( "\n" ) , newline, flush .

+5

, . , . IO.

0

According to the Clojure documentation , the default output will be reset for each new line. Therefore, you may have to explicitly clear the output in order to get what you want.

0
source

Source: https://habr.com/ru/post/1534962/


All Articles