Re: Unexpected nullpointer while processing a transient vector

2016-04-24 Thread Timothy Baldridge
Ack I somehow missed the code sample On Sunday, April 24, 2016, James Reeves wrote: > On 25 April 2016 at 03:27, Timothy Baldridge > wrote: > >> Transients are not thread safe.

Re: Unexpected nullpointer while processing a transient vector

2016-04-24 Thread James Reeves
On 25 April 2016 at 03:27, Timothy Baldridge wrote: > Transients are not thread safe. http://clojure.org/reference/transients It doesn't appear that they're being used across multiple threads. The code creates a transient, reduces over it, then makes it persistent. -

Re: Unexpected nullpointer while processing a transient vector

2016-04-24 Thread James Reeves
It's hard to tell for sure from your code sample, because you don't include "place" or "get-free-squares", but it's possible your error is in the reducing function here: (reduce #(when (not (keyword? %2)) (conj! %1 (if nxt {:board %2 :pawns (update

Unexpected nullpointer while processing a transient vector

2016-04-24 Thread Francis Avila
Your reduction function uses when, which returns nil for the false case. You need to use if instead and return %1 unchanged in the else case so the reduction can continue. There may still be other problems, but that is the cause of your NPE -- You received this message because you are

Re: Unexpected nullpointer while processing a transient vector

2016-04-24 Thread Timothy Baldridge
Transients are not thread safe. http://clojure.org/reference/transients On Sunday, April 24, 2016, Vandr0iy wrote: > Hi, Clojurists! > > I'm writing some clojure in these days, and I stumbled upon an error that > I'm unable to easily understand. > My goal is to

Unexpected nullpointer while processing a transient vector

2016-04-24 Thread Vandr0iy
Hi, Clojurists! I'm writing some clojure in these days, and I stumbled upon an error that I'm unable to easily understand. My goal is to asynchronously process a 2D vector in order to solve a parametric version of the 8 chess queens problem (where the parameters are: the board's dimensions and

Re: Processing an array

2016-04-24 Thread Paulus Esterhazy
Here's how I would do it: ``` (defn to-timed-events [events] (->> events (reduce (fn [[acc-events acc-time] {:keys [duration], :as event}] [(conj acc-events (assoc event :time acc-time)) (+ acc-time duration)]) [[] 0]) first)) ```

Re: Processing an array

2016-04-24 Thread 676c7473
Hello Olivier, perhaps 'reductions' would be a good fit here: (let [times (reductions + 0 (map :duration events))] (into [] (map #(assoc %1 :time %2) events times))) Best, -- David -- You received this message because you are subscribed to the Google Groups "Clojure" group. To

Processing an array

2016-04-24 Thread Olivier Scalbert
Hi all, I am a Clojure beginner And I have an advice to ask ! I have an array of events: (def events [ {:id "1" :duration 100} {:id "2" :duration 200} {:id "3" :duration 300} ]) I wanted to transform this array into: [ {:id 1, :duration 100, :time 0} ; event 1 starts at 0 {:id