1

I want to call a function every second.

I have the following code:

(defn dostuff []
  (do
    (print "I'm doing stuff")
    ...))

(while true
  (Thread/sleep 1000)
  (dostuff))

I would expect this to print "I'm doing stuff" every second but it does not.

How do I achieve this?

1
  • 1
    You are calling print instead of println. It doesn't auto-flush. Commented May 23, 2014 at 17:27

1 Answer 1

4

You're not flushing stdout. You can either use println, which is print plus newline (forces auto-flush), or explicitly call flush like this:

(defn dostuff []
  (do
    ...
    (print "I'm doing stuff")
    (flush)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.