Yeah, this is definitely an annoying bug.
On Thursday, April 10, 2014 8:03:02 PM UTC+8, Kevin Ilchmann Jørgensen
wrote:
>
> nREPL server started on port 53667 on host 127.0.0.1
> REPL-y 0.3.0
> Clojure 1.5.1
> Docs: (doc function-name-here)
> (find-doc "part-of-name-here")
> Source: (source function-name-here)
> Javadoc: (javadoc java-object-or-class-here)
> Exit: Control+D or (exit) or (quit)
> Results: Stored in vars *1, *2, *3, an exception in *e
>
> *user=> (source println)*
> (defn println
> "Same as print followed by (newline)"
> {:added "1.0"
> :static true}
> [& more]
> (binding [*print-readably* nil]
> (apply prn more)))
> nil
> *user=> (source prn)*
> (defn prn
> "Same as pr followed by (newline). Observes *flush-on-newline*"
> {:added "1.0"
> :static true}
> [& more]
> (apply pr more)
> (newline)
> (when *flush-on-newline*
> (flush)))
> nil
> *user=> (source printf)*
> (defn printf
> "Prints formatted output, as per format"
> {:added "1.0"
> :static true}
> [fmt & args]
> (print (apply format fmt args)))
> nil
> *user=> (source print)*
> (defn print
> "Prints the object(s) to the output stream that is the current value
> of *out*. print and println produce output for human consumption."
> {:added "1.0"
> :static true}
> [& more]
> (binding [*print-readably* nil]
> (apply pr more)))
> nil
> *user=> (source pr)*
> (defn pr
> "Prints the object(s) to the output stream that is the current value
> of *out*. Prints the object(s), separated by spaces if there is
> more than one. By default, pr and prn print in a way that objects
> can be read by the reader"
> {:dynamic true
> :added "1.0"}
> ([] nil)
> ([x]
> (pr-on x *out*))
> ([x & more]
> (pr x)
> (. *out* (append \space))
> (if-let [nmore (next more)]
> (recur (first more) nmore)
> (apply pr more))))
> nil
> *user=> *flush-on-newline**
> true
> user=>
>
>
> On Thu, Apr 10, 2014 at 1:50 PM, Cecil Westerhof <[email protected]
> <javascript:>> wrote:
>
>> 2014-04-10 13:40 GMT+02:00 Di Xu <[email protected] <javascript:>>:
>>
>> there're three buffer mode in unix, line buffered, full buffered and no
>>> buffered, if the output is terminal then it's default to line buffered.
>>> That means it buffer the output until '\n' occurs, you can force output via
>>> flush.
>>>
>>
>> The printf format string is "%s: %s\n", so there is a newline, but it is
>> not acted upon.
>>
>>
>>
>>> 2014-04-10 19:30 GMT+08:00 Cecil Westerhof <[email protected]
>>> <javascript:>>:
>>>
>>>> 2014-04-10 12:52 GMT+02:00 Kevin Ilchmann Jørgensen <[email protected]
>>>> <javascript:>>:
>>>>
>>>> I believe this is how the terminal behave. You can force an
>>>>> (clojure.core/flush)
>>>>>
>>>>
>>>> But why does println not behave this way?
>>>>
>>>> I think I stick to println for the moment.
>>>>
>>>>
>>>> On Thu, Apr 10, 2014 at 12:34 PM, Cecil Westerhof <[email protected]
>>>>> <javascript:>> wrote:
>>>>>
>>>>>> I have the following simple program:
>>>>>> (def time-format (new java.text.SimpleDateFormat "hh:mm:ss"))
>>>>>>
>>>>>> (defn now []
>>>>>> (new java.util.GregorianCalendar))
>>>>>>
>>>>>> (defn give-message [message]
>>>>>> (printf
>>>>>> "%s: %s\n" (. time-format format (. (now) getTime)) message))
>>>>>>
>>>>>> (give-message "Start")
>>>>>> (doseq [i (range 1 100000001)]
>>>>>> (let [val (Math/sqrt i)
>>>>>> diff (Math/abs (- (Math/pow val 2) (* val val)))]
>>>>>> (when-not (< diff 1.5E-8)
>>>>>> (println (format "Different for %d (%e)" i diff)))))
>>>>>> (give-message "Stop")
>>>>>>
>>>>>> It does what it should, but I have a little problem with it: the
>>>>>> output of give-message is only showed after terminating the program. Why
>>>>>> is
>>>>>> that?
>>>>>>
>>>>>> When changing give-message to:
>>>>>> (defn give-message [message]
>>>>>> (println (format "%s: %s" (. time-format format (. (now)
>>>>>> getTime)) message)))
>>>>>>
>>>>>> the output is shown immediately.
>>>>>>
>>>>>
>> --
>> Cecil Westerhof
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.