Reputation: 1478
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?
Upvotes: 1
Views: 2224
Reputation: 8593
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
Upvotes: 7