stream - How to create a simple userprompt in clojure -
consider simple function definition in clojure:
(defn prompt [] (print ">>> ") (read-line)) my ambition let user enter string prepended prompt-prefix. however, seems read-line gets executed before print statement. however, flushing output stream
(defn prompt [] (print ">>> ") (flush) (read-line)) this function works intended. why manually have flush out in order ">>> " written out? according docs, functions , do should execute expressions in order.
they executed in order. executing print doesn't mean given output flushed whatever stream *out* variable pointing to. docs say, print function
prints object(s) output stream current value of *out*.
and default, *out* points printwriter target of system.out. printwriter instances, flushing isn't enabled default. although, can enable auto-flush via using certain constructors creating instance.
even then, printwriter instances:
if automatic flushing enabled done when 1 of println, printf, or format methods invoked, rather whenever newline character happens output.
Comments
Post a Comment