5

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.

2
  • Just fyi, at github.com/stuarthalloway/programming-clojure/tree/master Halloway includes a copy of clojure and clojure-contrib that are the versions he uses for the book in it's current form. Commented Feb 4, 2009 at 22:29
  • Yeah, those are the ones that failed. Commented Feb 5, 2009 at 2:12

2 Answers 2

3

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"
Sign up to request clarification or add additional context in comments.

2 Comments

Yes sir that was the problem! Thanks!
Of course. Clojure's been changing a lot lately so I've run into a lot of similar problems between the first beta of the book and the current beta (but apparently this will calm down a bit soon).
1

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

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.