That was it. I didn't think that calling the method directly on the
record would use reflection.
(dotimes [_ 10] (time (dotimes [_ 1] (m1 my-simple-P "hello"
"Elapsed time: 14.765 msecs"
"Elapsed time: 5.347 msecs"
"Elapsed time: 21.427 msecs"
"Elapsed time: 7.267 msecs"
"Elapsed time: 2.
Hi,
Am 21.08.2010 um 07:33 schrieb Toni Batchelli:
> (dotimes [_ 10] (time (dotimes [_ 1] (.m1 my-simple-P "hello" ;
>
> "Elapsed time: 131.973 msecs"
I think you get caught by reflection here. As Nicholas said, you should call
m1, not .m1.
Sincerely
Meikel
--
You received this me
m1 I meant.
Apologies.
On Sat, Aug 21, 2010 at 8:36 AM, Nicolas Oury wrote:
> On Sat, Aug 21, 2010 at 6:33 AM, Toni Batchelli wrote:
>> P-impl.))
>> (dotimes [_ 10] (time (dotimes [_ 1] (.m1 my-simple-P "hello" ;
>> "Elapsed time: 131.973 msecs"
>> "Elapsed time: 142.72 msecs"
>> "Elaps
On Sat, Aug 21, 2010 at 6:33 AM, Toni Batchelli wrote:
> P-impl.))
> (dotimes [_ 10] (time (dotimes [_ 1] (.m1 my-simple-P "hello" ;
> "Elapsed time: 131.973 msecs"
> "Elapsed time: 142.72 msecs"
> "Elapsed time: 95.51 msecs"
> "Elapsed time: 95.724 msecs"
> "Elapsed time: 83.646 msecs"
C
So it looks I made a young programmer mistake (and I am not that young
anymore!) I *assumed* that creating a defrecord would result in faster code
than extending an existing one and therefore was looking to perform an early
(and thus unnecessary) optimization. According to the code and results
belo
Hi Meikel,
This is awesome! You just did a big chunk of what I was about to try
to do :). Sorry for the late response, I've been off the grid for a
few days...
With your second proposed solution, the defrecord-with-defaults macro,
one can achieve very good performance while keeping some of the
f
Hi,
one way to do that is using extend.
(def defaults
{fn1 (fn ...)
fn2 (fn ...)
fn3 (fn ...)})
(defrecord R1 [...])
(def R1-fns
{fn1 (fn ...)})
(defrecord R2 [...])
(def R2-fns
{fn2 (fn ...)
fn3 (fn ...)})
(extend YourProtocol
R1 (merge defaults R1-fns)
R2 (merge defaults R
Hi Toni,
The key thing is that you can implement protocol on Object.
So if you have one protocol per function, (Let's call your function f1,...,
fn and the protocols implementing them F1,,Fn)
You can define a default value for each function:
(extend-type Object
F1 (f1 ...) Fn (fn)
Hi Nicolas,
I get the idea, but I don't see how this would help provide a default
implementation for the functions inside a protocol. It looks to me
like this would be the same as creating a record with only some of the
functions implemented. Or am I reading it wrong?
Thanks for your input.
Toni
I read my mail and couldn't understand it.
Here is what I meant:
(defprotocol MessageReceived
(message-received ...))
(defprotocol ExceptionCaught
.)
(extend Object MessageReceved {:message-received
default-message-received-function}...
)
(deftype channel-handler
ExceptionCaught
Not very clean suggestion.
Split the protocol in one protocol per function.
Instance every one on Object, with the default protocol.
Instance each specific on the function for which it has a special instance.
On Fri, Jul 16, 2010 at 7:45 PM, tbatchelli wrote:
> Hi all,
>
> I am writing a netw
Hi all,
I am writing a network protocol handler based on events (to wrap
netty, if you're curious). I created a protocol that defines the
functions needed to handle every possible (channel) event:
(defprotocol channel-handler-strategy
(message-received [this ctx evt])
(exception-caught [this
12 matches
Mail list logo