While (read) taking an argument seems valid, I think you can do what you want in the short term using binding:
(binding [*in* my-reader] (print (read))) It has been my general observation that vars + binding in Clojure fill the niche that optional arguments fill in other languages. While it may seem like more work to create a binding around a function than to pass an optional argument, you only have to do it once for many calls to read. Plus, if you are calling functions that in-turn call read, your binding will persist. This may or may not be the behavior you want, but it is certainly powerful. This style of programming tends to decrease the amount of "tramp data" passed around. I for one am really enjoying it. I never thought I would be such a fan of dynamic scope. ;-) IIRC, duck-streams has a (with-reader ...) form that will handle the binding and close the reader when it exists (which may or may not be what you want). Cheers, _Mark On Thu, Feb 12, 2009 at 11:53 AM, Phil Hagelberg <p...@hagelb.org> wrote: > > > I've got a problem where I have a reader (it's a java.io.BufferedReader > that came from duck-streams, if that matters at all) and I want to call > "read" on it. > > I'd expect to be able to do (read (reader my-file)), but this isn't OK > because read needs a java.io.PushbackReader. It seems vaguely wrong > somehow to have a function called "reader" return something that cannot > be "read" from. > > I took a look at what could be done to fix this. I looked at the clj > definition of read, but it looks like you'd have to turn it into a > multimethod to make it accept readers that aren't PushbackReaders. Since > read is such a fundamental function, this seems ill-advised. But it > looks to me that you could also solve this problem by adding a method to > clojure.lang.LispReader that could accept other kinds of readers and > wrap them in a PushbackReader without modifying any existing code. > > Does this seem like a decent idea? I'm fine if the correct answer is > just "quit your whining, it's not that bad", but I'd like to know if I'm > the only person this bothers--at least in that case I can attempt to > adjust my aesthetics. =) > > -Phil > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---