Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark Engelberg
Yeah, you've answered your own question. In practice, I doubt the difference is measurable. Another common idiom you see in Clojure code is: (defn f [xs] (if-let [s (seq xs)] ...do something with (first s) and (f (rest s))... ...base case...)) This ensures that you seq-ify the input (r

Re: Future of performant software: cores or memory?

2014-07-17 Thread Mark Phillips
Hi Gary, I wrote my initial post in January, but I just wanted to say... Thanks for taking the time to write your reply - I very much appreciated it. I suspect I will be writing algorithms in C++ for a while to come, but at some point I hope to do comparisons with Clojure versions. Regards,

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark Phillips
I *think* I've found the answer to my own question... In this post... https://groups.google.com/forum/#!topic/clojure/Cuk_bJrIq-Y I found this link (I changed the line number)... https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L2589 And if the implementat

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark Phillips
Thanks again - that all makes sense. One (hopefully) tiny question... an efficiency one... (and feel free not to answer it if I've already taken up enough of your time) If you do that and are careful, the performance of next/nil? is slightly > better than rest/empty?. > If I use the next/nil?

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark Engelberg
On Thu, Jul 17, 2014 at 7:54 PM, Mark P wrote: > > I notice in your lazy version (below), you preface the last cons with a > lazy-seq call, but do not do the same with the other cons calls (within the > first recur form). I know it was only the last line that previously had a > conj call and so

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark P
One other question occurs to me re your comment... It's worth understanding how to go back and forth between accumulator-style > and a lazy construction. You can convert the above non-lazy accumulator > version into a similar version that is lazy but has no risk of stack > overflow in the real

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark P
Woopse, typo towards the end of my last post... Maybe the thing to do would be to use (next x) here for this > implementation, which is angling to be lazy... But in your earlier > acc-based my-flatten, to use (next x) instead > Should be... Maybe the thing to do would be to use (rest x) ...

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark P
Coming back to your helpful comments about relationship between acc-style and lazy... It's worth understanding how to go back and forth between accumulator-style > and a lazy construction. You can convert the above non-lazy accumulator > version into a similar version that is lazy but has no r

ANN Pantomime 2.3.0 is released

2014-07-17 Thread Michael Klishin
Pantomime [1] is a tiny Clojure library for working with MIME types. Release notes: http://blog.clojurewerkz.org/blog/2014/07/18/pantomime-2-dot-3-0-is-released/ 1. https://github.com/michaelklishin/pantomime --   -- You received this message because you are subscribed to the Google Groups "C

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Raoul Duke
> http://clojure.org/reducers i dare say the "When to use" part should not be at the bottom but come right after the otherwise laughably specious "yielding code that will get faster automatically as machines get more cores". -- You received this message because you are subscribed to the Google G

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Steve Miner
Slightly off-topic from original poster's question, but if you're interested in another implementation of flatten, I suggest you take a look at the reducers library. clojure.core/flatten is elegant but a bit slow. The reducers version is very fast as part of a reduce/fold operation. The whol

Re: Critiques of "my-flatten" which uses CPS

2014-07-17 Thread Mark Engelberg
Right. Overall lessons: In recursion, the call stack automatically keeps track of what still needs to be done. In Clojure, due to Java, the stack is significantly more limited than heap, so this can be a real limitation. To break free of that limitation, you must somehow keep track of what still

Re: Unexpected ClassCastException when passing generics

2014-07-17 Thread Vladimir Bokov
Thanks a lot! I really didn't get the sense of [L But still, I think it's very counterintuitive, I'd expect cast org.freedesktop.dbus.Message$StringMethodArgument to org.freedesktop.dbus.Message$MethodArgument[] error message (at least) or something more verbose than chars "[L" пятница, 18 июля

Re: Unexpected ClassCastException when passing generics

2014-07-17 Thread Sean Corfield
On Jul 17, 2014, at 11:18 AM, Vladimir Bokov wrote: > I'm trying to communicate with DBus via https://github.com/cathive/fx-dbus > java lib, but > passing an object which extends java abstract generic inner class complains, > that it cannot be cast > to parent class: > > ClassCastException Cann

Unexpected ClassCastException when passing generics

2014-07-17 Thread Vladimir Bokov
I'm trying to communicate with DBus via https://github.com/cathive/fx-dbus java lib, but passing an object which extends java abstract generic inner class complains, that it cannot be cast to parent class: ClassCastException Cannot cast org.freedesktop.dbus.Message$StringMethodArgument to [Lor

Re: Calculating the number of timestamps logged within a specific time period

2014-07-17 Thread Ashish Negi
You need not reverse the list for counting requests per second. If the data is in sorted order, you can start with any direction. Take the first as the base and keep separating untill you get 1 second or X units like 1000 milliseconds if your data is in milliseconds. The count would be an item of

Re: Calculating the number of timestamps logged within a specific time period

2014-07-17 Thread Mike Fikes
As a start, you could use group-by with a function that squashes together items that fall in the same second and then count the size of each value. (reduce-kv (fn [c k v] (assoc c k (count v))) {} (group-by #(quot % 1000) epochs)) ;=> {1405060205 1, 1405060200 1, 1405060201 8, 1405060202 1} -

Calculating the number of timestamps logged within a specific time period

2014-07-17 Thread emptya45
Hi, I have a list of epoch times which map to HTTP requests. '(1405060202611 1405060201157 1405060201361 1405060201261 1405060200391 1405060201458 1405060201705 1405060201058 1405060205062 1405060201558 1405060201761 ) I am trying to find out how many HTTP requests I have in a specified ti

Re: Scheduling state change?

2014-07-17 Thread Colin Fleming
I agree with Michael. Specifically, the ScheduledExecutorService is probably what you want. Note that Clojure functions implement Runnable, so you can pass one directly to the executor. Cheers, Colin On

Re: Scheduling state change?

2014-07-17 Thread Michael Klishin
On 17 July 2014 at 14:40:57, Thomas (th.vanderv...@gmail.com) wrote: > > Any ides how best to achieve this in Clojure? I already had a look > at the various scheduling libraries (at-at, cronj and Quartzite), > but from what I understand they don't support this behaviour, > but please correct

Scheduling state change?

2014-07-17 Thread Thomas
Hi, I would like to schedule updates to a state machine (eg. move each second to a new state and do something) and I will have potentially 10.000+ of these state machines. Ideally I would like to do something like this: (defn my-func [state] (let [new-state (do-something state)] (schedule