Re: Redubicle NIO

2012-10-19 Thread Herwig Hochleitner
> - Herwig Holchleitner: how would that solution with protocols be? I write > a protocol that defines methods like `get` and `duplicate` and extend it > for each buffer, delegating the methods to their specific implementations? > ie, (defprotocol UnifiedBuffers (get [buff] "get data from buf") (du

Re: Redubicle NIO

2012-10-18 Thread Bruno França dos Reis
So, the current version, after the suggestion by Alan Malloy, is the following: (defmacro buffer-reduce [b f val] `(let [b# (.duplicate ~b) f# ~f] (loop [remaining# (.remaining b#) result# ~val] (if (zero? remaining#) result# (recur (dec remain

Re: Redubicle NIO

2012-10-18 Thread David Nolen
On Thu, Oct 18, 2012 at 7:15 PM, Herwig Hochleitner wrote: > 2012/10/19 Bruno França dos Reis > >> The reason why I wrote a macro instead of a function is because 'get' and >> 'duplicate' are not declared in any common superclass of the different >> buffers, so I was getting lots of reflection! >

Re: Redubicle NIO

2012-10-18 Thread Herwig Hochleitner
2012/10/19 Bruno França dos Reis > The reason why I wrote a macro instead of a function is because 'get' and > 'duplicate' are not declared in any common superclass of the different > buffers, so I was getting lots of reflection! > > Are there alternatives to the macro that avoid reflection? > Y

Re: Redubicle NIO

2012-10-18 Thread Bruno França dos Reis
Thanks for the input. Didn't know that I was multiply-evaluating f. The reason why I wrote a macro instead of a function is because 'get' and 'duplicate' are not declared in any common superclass of the different buffers, so I was getting lots of reflection! Are there alternatives to the macro th

Re: Redubicle NIO

2012-10-18 Thread Alan Malloy
As a general-macro aside, you are multiply-evaluating the `f` argument, by expanding it in-place inside the recursive clause. This is almost certainly not what you want, and you could avoid it by starting with (let [f# ~f] ...). Better still, ask why this is a macro at all. This should really just

Re: Redubicle NIO

2012-10-18 Thread Bruno França dos Reis
Damn, just noticed a small mistake in the macro: I use the original buffer, not the duplicated one. Here's the correct version: (defmacro buffer-reduce [b f val] `(let [b# (.duplicate ~b)] (loop [remaining# (.remaining b#) result# ~val] (if (zero? remaining#) re

Redubicle NIO

2012-10-18 Thread Bruno França dos Reis
Hello! I've recently started playing with Clojure, and a couple of days ago I've been pointed to Reducers in Clojure 1.5 after a discussion on #clojure at Freenode. I've read Rich's posts announcing the Reducers library, and he says that there's a ***lack of reducible IO sources***. I'm workin