beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
roelof 2020-12-18T09:23:13.451500Z

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 [] 
  (dosync
   (let [first (first work)
         rest (rest work)]
     alter sum4 + first)
   ))

2020-12-18T10:58:24.452900Z

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

2020-12-18T11:00:28.453600Z

also, you should update work in your code

2020-12-18T11:00:51.454100Z

and alter sum4 + first is missing parens now

roelof 2020-12-18T11:06:22.457Z

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

2020-12-18T11:13:03.461200Z

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

phoenixjj 2020-12-18T11:13:05.461400Z

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.

2020-12-18T11:14:11.462100Z

such that both sum and work are updated in the transaction

2020-12-18T11:14:46.462800Z

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

2020-12-18T11:19:19.464200Z

@phoenixai2082 did you try profiling or sampling in visualvm?

phoenixjj 2020-12-18T11:20:48.464700Z

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

2020-12-18T11:22:28.465300Z

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?

2020-12-18T11:23:17.466300Z

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...

val_waeselynck 2020-12-18T11:26:04.466400Z

clj-async-profiler

✅ 1
jumar 2020-12-18T12:18:01.466800Z

^ That's a good one. Assuming that the bottleneck is CPU. Here's a very recent and long webinar about Async Profiler https://www.youtube.com/playlist?list=PLNCLTEx3B8h4Yo_WvKWdLvI9mj1XpTKBr

jumar 2020-12-18T12:28:28.467100Z

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.

bnstvn 2020-12-18T13:09:43.469Z

what does a symbol do in a function position?

('+ 1 2)
=> 2

bnstvn 2020-12-18T13:19:54.469100Z

ah, like keyword

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

👍 1
bronsa 2020-12-18T13:32:31.471700Z

it looks itself up on the first argument

bronsa 2020-12-18T13:32:52.472400Z

the second argument is not-found

👍 1
Tuan-Anh 2020-12-18T13:33:05.472700Z

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?

Tuan-Anh 2020-12-18T13:33:40.473Z

Any advices/help would be greatly appreciated!

borkdude 2020-12-18T13:34:23.473300Z

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

Tuan-Anh 2020-12-18T14:26:55.475300Z

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

2020-12-18T14:34:35.476600Z

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

✅ 2
Tuan-Anh 2020-12-18T15:21:57.477700Z

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

👍 1
phoenixjj 2020-12-18T17:50:33.484300Z

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