On 28 August 2010 22:14, evins.mi...@gmail.com <evins.mi...@gmail.com> wrote:
> I was actually asking how to avoid doing what you did :-). If it's
> necessary to do it, that's fine, but I thought I'd ask first, in case
> there was a way around it that I hadn't noticed.

Well, some level of reimplementation will probably be necessary (if
there is an implementation of an "indexing reader" in the base class
libraries, I'd love to learn about it, but I don't think there is!).

Having said that, you could take Robert's approach and have the proxy
implement a new interface (which you can define through definterface)
to check current offset:

;;; untested...

(definterface IReaderOffset
  (^int readerOffset []))

;;; and the proxy form:
(proxy [java.io.PushbackReader IReaderOffset] [...]
  (read ...)
  (unread ...)
  (readerOffset [] @*current-char-number*))

;;; also, drop the final (fn ...) form from read-with-number --
;;; return the proxy itself instead; maybe also rename
;;; to e.g. indexing-reader?

Then you could use the regular read function and say (.readerOffset
reader-instance) to find out what the current index is. This does at
least have the nice property that you can ignore the extra information
when it's not needed (as you could with multiple return values in CL).

Sincerely,
Michał

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

Reply via email to