Moving average from Java to Clojure

2014-07-20 Thread Cecil Westerhof
I just wrote a moving average class in Java: https://github.com/CecilWesterhof/JavaExamples/blob/master/MovingAverageQueue.java I was just wondering: what is the best way to translate this to Clojure? At the moment Clojure does not have a queue. Should I just use the Java calls, or is there a be

Re: Moving average from Java to Clojure

2014-07-20 Thread Plínio Balduino
Hi Cecil Clojure has a clojure.lang.PersistentQueue to work with queues. I don't know why it doesn't have a reader macro, but works fine and returns you a Clojure collection you can handle with cons and peek. You can start with an empty queue with clojure.lang.PersistentQueue/EMPTY or insert y

Re: Moving average from Java to Clojure

2014-07-20 Thread Mike Fikes
There actually is a queue implementation. Here is a way to use it for your problem: (defn make-moving-average-queue [n] (atom {:lengthn :current-total 0.0 :old-values(clojure.lang.PersistentQueue/EMPTY)})) (defn update-moving-average-queue [old-queue next-value]

Re: Moving average from Java to Clojure

2014-07-20 Thread Mike Fikes
Hey Cecil, In addition to using peek instead of first, as indicated by Plinio, the moving-average function above uses some poor names, in hindsight, especially the "old-queue" parameter name. I'd suggest naming it queue, as it refers to an atom. You could even consider naming the function mov

Re: Moving average from Java to Clojure

2014-07-20 Thread Jony Hudson
On Sunday, 20 July 2014 12:48:19 UTC+1, Cecil Westerhof wrote: > or is there a better way? > Probably not the answer you're looking for, but the exponentially-weighted moving average doesn't require any state other than the current value: (defn ewma [alpha] (fn [avg new] (+ (* (- 1 alpha) avg)

ANN How to Make Your Open Source Project Really Awesome, part 2

2014-07-20 Thread Michael Klishin
15 months ago we wrote what ended up being quite a popular post on the ClojureWerkz blog: http://blog.clojurewerkz.org/blog/2013/04/20/how-to-make-your-open-source-project-really-awesome/ and now part 2 is up: http://blog.clojurewerkz.org/blog/2014/07/20/how-to-make-your-open-source-project-reall

[jobs] for newbie in europe

2014-07-20 Thread Krzysztof Władyka
Hello, I am living in Poland and i have a little problem there... totally 0 jobs for Clojure Programmers. I am also beginner in Clojure. More about my IT skills you can read on site http://wladyka.eu/ . Do you know any option to get a job in Europe or remotely if i don't have any seriously ex

Re: [jobs] for newbie in europe

2014-07-20 Thread Aaron France
Where are you based? On Sun, Jul 20, 2014 at 4:29 PM, Krzysztof Władyka wrote: > Hello, > > I am living in Poland and i have a little problem there... totally 0 jobs > for Clojure Programmers. > > I am also beginner in Clojure. More about my IT skills you can read on > site http://wladyka.eu/ .

Stumped: unable to resolve symbol in macro expansion

2014-07-20 Thread Matthew DeVore
I don't have a Clojure REPL handy at the moment but it looks like the x symbol is being resolved in the macro context rather than the expansion context. In the macro source, where you have a plain x, try to replace it with ~'x ... This blog post may be relevant: http://amalloy.hubpages.com/hub/

Database schema Heroku and Node-Webkit

2014-07-20 Thread Jonathon McKitrick
I'm developing an app that will initially run on Heroku, but will eventually migrate to a Node-Webkit app. What would you suggest is the simplest way to create and maintain a schema that would work well on both a Heroku app (with PostGres) and a Node-Webkit app (perhaps Sqlite or another altern

positional + keyword args

2014-07-20 Thread Sam Raker
I'm trying to write a function that takes (up to) 4 arguments. I want to be able to supply every argument positionally, with a keyword or as a default, so that (f) (f 1) (f 1 2) (f 1 2 3) (f 1 2 3 4) (f 1 :b 2) (f 1 2 :c 3) ... (f :a 1 :b 2 :c 3 :d 4) are all equivalent. In Python, I could do t

Re: positional + keyword args

2014-07-20 Thread Alex Baranosky
You can get keyword args like this: (defn f [& {:keys [a b c d] :or {a 1 b 2 c 3 d 4}}] [a b c d]) But you cannot also get the ability to call: (f 5 6 7 8) On Sun, Jul 20, 2014 at 4:13 PM, Sam Raker wrote: > I'm trying to write a function that takes (up to) 4 arguments. I want t

Re: positional + keyword args

2014-07-20 Thread Sam Raker
I hacked this together: (defn f [& args] (let [default-args-atom (atom {:a 1 :b 2 :c 3 :d 4}) kwds (vec (keys @default-args-atom)) kwargs (map-indexed (fn [idx arg] (if (keyword? arg) (swap! default-args-atom assoc arg (get args (inc idx))) (swap! a assoc (get kwds

Re: positional + keyword args

2014-07-20 Thread Sam Raker
Wait. Should be: (defn f [& args] (let [default-args-atom (atom {:a 1 :b 2 :c 3 :d 4}) kwds (vec [:a :b :c :d) kwargs (map-indexed (fn [idx arg] (if (keyword? arg) (swap! default-args-atom assoc arg (get args (inc idx))) (swap! a assoc (get kwds idx) arg))) args)]

Re: positional + keyword args

2014-07-20 Thread Sam Raker
Wait. Should be: (defn f [& args] (let [default-args-atom (atom {:a 1 :b 2 :c 3 :d 4}) kwds [:a :b :c :d] kwargs (map-indexed (fn [idx arg] (if (keyword? arg) (swap! default-args-atom assoc arg (get args (inc idx))) (swap! a assoc (get kwds idx) arg))) args)] (

Re: positional + keyword args

2014-07-20 Thread Sam Raker
Nope, that doesn't actually work... On Sunday, July 20, 2014 8:57:47 PM UTC-4, Sam Raker wrote: > > Wait. Should be: > > (defn f [& args] (let [default-args-atom (atom {:a 1 :b 2 :c 3 :d 4}) kwds > [:a :b :c :d] > kwargs (map-indexed (fn [idx arg] (if > (keyword? ar

Re: positional + keyword args

2014-07-20 Thread Sam Raker
OK! After a few false starts, I think I got it: (defn f [& args] (let [args (vec args) default-args-atom (atom {:a 1 :b 2 :c 3 :d 4}) kwds [:a :b :c :d]] (do (dorun (map-indexed (fn [idx arg] (if (keyword? arg)