Clojure read-line函数问题 [英] Clojure read-line function problem

查看:150
本文介绍了Clojure read-line函数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Clojure程序中获取控制台输入,但当它给我这个错误,当它到达程序的那部分。

 线程main中的异常java.lang.ClassCastException:
clojure.lang.LineNumberingPushbackReader不能转换为java.io.BufferedReader
pre>

'read'函数工作,但它不是我需要的。这是我使用的代码。

 (defn prompt-read [ %s:prompt))
(flush)
(read-line))

编辑:



这显然只是我使用的版本。这是版本包括在编程Clojure的当前示例代码,我将测试当前版本,看看是否是这个问题。

解决方案

嗯,它似乎为我工作。你使用什么版本的Clojure,你如何调用prompt-read?这里是我回来了(这里 goo 是我的回应):

  user => (defn prompt-read [prompt] 
(print(format%s:prompt))
(flush)
(read-line))
#'user / prompt -read
user => (提示符foo)
foo:goo
goo


I'm trying to get console input in my Clojure program, but when it gives me this error when it gets to that part of the program.

Exception in thread "main" java.lang.ClassCastException:
clojure.lang.LineNumberingPushbackReader cannot be cast to java.io.BufferedReader

the 'read' function works, but it's not what I need. Here is the code I'm using.

(defn prompt-read [prompt]
  (print (format "%s: " prompt))
  (flush )
  (read-line))

EDIT:

It is obviously just the version I'm using. It's the version included in the current sample code of Programming Clojure, I'll test out the current release version and see if that is the problem.

解决方案

Hmm, it seems to work for me. What version of Clojure are you using and how are you calling prompt-read? Here's what I'm getting back (here goo is my response):

user=> (defn prompt-read [prompt]
(print (format "%s: " prompt))
(flush )
(read-line))
#'user/prompt-read
user=> (prompt-read "foo")
foo: goo
"goo"

这篇关于Clojure read-line函数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆