在Clojure中格式化输入提示

在Clojure中格式化输入提示,clojure,Clojure,我试图在Clojure中创建一个简单的输入循环。我们的想法是阅读一行文本,如下所示: > look You see nothing, as this game hasn't actually been written. 我尝试使用的方法如下: (defn get-input [] (print "> ") (string/trim-newline (read-line))) 但是,输入循环看起来是这样的: look > You see nothing, as thi

我试图在Clojure中创建一个简单的输入循环。我们的想法是阅读一行文本,如下所示:

> look
You see nothing, as this game hasn't actually been written.
我尝试使用的方法如下:

(defn get-input []
  (print "> ")
  (string/trim-newline (read-line)))
但是,输入循环看起来是这样的:

look
> You see nothing, as this game hasn't actually been written.

如何在用户输入之前而不是之后打印角度引号?

这是一个缓冲问题<代码>“>”只是一小部分文本,并且不包含换行符(由于您没有使用
println
,因此不会自动添加换行符),因此它会卡在扩展缓冲区中。您只需在
print
ing之后执行
flush

当我在多个地方需要这样的
打印
/
刷新
组合时,我通常会创建一个小助手函数来整理东西:

(defn print-fl [& messages]
  (apply print messages) ; Pass the strings to print to be printed
  (flush)) ; Then flush the buffer manually so small strings don't get stuck

(defn get-input []
  (print-fl "> ")
  (string/trim-newline (read-line)))

(get-input)
> look
"look"