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