Fork me on GitHub

I have this challenge from the book "Clojure from the ground up"

Write a function which, in a dosync transaction, removes the first number in work and adds it to sum.
Then, in two futures, call that function over and over again until there's no work left. Verify that @sum is 4999950000
anyone a idea what the two futures should do and why 2 futures So far I have this :
(def work (ref (apply list (range 1e5))))

(def sum4 (ref 0))

(defn sum_sync [] 
   (let [first (first work)
         rest (rest work)]
     alter sum4 + first)


the 2 futures execute the processing in separate threads, i guess it is to demonstrate that changes within a transaction are atomic


also, you should update work in your code


and alter sum4 + first is missing parens now


oke, so one future for updating sum and one for removing a item from work ? @chrisblom


no, write a function that takes one item from the work list, adds it to the sum


How to check for performance issue or where time is being spent? I have 2.3 million rows in db. Loaded one column of big decimal type and running cumulative sum on it and then passing it to incanter line charts. It's been going on more than an hour, but no result so far.

> (def csum (cumulative-sum
           (map #(:resp %)
                (jdbc/execute! ds ["select resp from train_data"]
                               {:builder-fn rs/as-unqualified-lower-maps}))))

> (charts/line-chart (range 0 (count csum)) csum)
Using Visualvm I can see on heapspace chart moving up and down. also object count is pretty much constant by looking at multiple heap dump. Only 8GB of ram is used and also htop shows only 1 core active out of 8.


1. csum is fully realized at the point you call line-chart? 2. If you evaluate all the 2M rows I guess incanter can have issues producing a chart with so many values.


yes. It is taking around 6 minutes to produce 100K charts.


such that both sum and work are updated in the transaction


then call that function in 2 futures until the work list is empty


@phoenixai2082 did you try profiling or sampling in visualvm?


tried profiling, but it is stuck at 75% from 40 minutes


As a brand new Clojure programmer and IntelliJ/Cursive user... How do I profile my code to figure out what is eating up CPU cycles or allocations?




^ That's a good one. Assuming that the bottleneck is CPU. Here's a very recent and long webinar about Async Profiler


I can get my code running with a "Run/Debug Configuration" no problem, but the "Run with CPU profiler" option tells me Deferred configurations cannot be run with standard runners and I'm not sure I get what that means...


what does a symbol do in a function position?

('+ 1 2)
=> 2


ah, like keyword

('+ {'+ :hmm})
=> :hmm

👍 3

it looks itself up on the first argument


the second argument is not-found

👍 3

Hi, I don't know if this is the right channel to ask this but here goes I'm planning on developing a mobile app. I could just work with JavaScript and React Native, but I want to try ClojureScript with React Native. Does anyone here have any experience developing mobile app with ClojureScript and React Native, either through work or personal project? I would love to know what framework I should use. I've been doing research but seems like re-natal is no longer maintained and krell is too early in development with not that much documentation?


Any advices/help would be greatly appreciated!


@tuananh.le #cljsrn would be the channel for React Native + CLJS


Gotcha, thanks @borkdude, I will post my question there

Michaël Salihi14:12:35

@tuananh.le Yes and in addition to the channel, you add this website/page There have been 2 very good videos recently added in the "Talks & Videos" section.


Thank @UFBL6R4P3! I will check out that webpage and watch those videos.

👍 3