Rayne
Rayne

Reputation: 32625

Clojure read-line function problem

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.

Upvotes: 5

Views: 3575

Answers (2)

Someguy
Someguy

Reputation:

The read-line problem was a known bug. It was fixed. Update your Clojure version.

Upvotes: 1

Chris Bunch
Chris Bunch

Reputation: 89823

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"

Upvotes: 3

Related Questions