1

Complete Clojure newbie here so I'm probably missing something fundamental about the way clojure works but I'm not understanding the way Clojure evaluates functions.

(defn get-output [] 
  (print "Enter: Width <RTN> Height <RTN> Price <RTN> Shape <RTN>")
  (print (calculate (read-string (read-line))))

I'm used to a language like Ruby or C where the first print function would be evaluated, printing the string to the terminal. Then the second print function would be evaluated, prompting the user for input.

However, what actually happens is that the terminal first prompts the user for input and prints "Enter: Width Height Price Shape " after. Finally the program outputs the return value from calculate.

Why are these print statements not executing as I expect?

1 Answer 1

7

The statements are executing in the order that you expect. The issue is that print doesn't flush the out buffer. You can either call (flush) after the first print statement or perhaps you want to call println

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.