That's a neat improvement to be able to ignore the value when you
don't need it, thanks Michał Marczyk.

Also, though both proxies happen to work with clojure's (read)  function,
every read operation of the pushback reader would have to be wrapped
in the variable changing code
to guarantee correctness in all cases.  So the proxy needs about 3-5
more methods to be a complete covering.

you wouldn't want me to do
(.skip reader 5)

and have *current-char-number* become wrong!

The perils of mutable state are made of this... :(

>From a code reuse standpoint, isn't this kinda lame?

--Robert McIntyre

On Sat, Aug 28, 2010 at 5:28 PM, Michał Marczyk
<michal.marc...@gmail.com> wrote:
> 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

-- 
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