Fork me on GitHub

hello, how to solve this -> [[a b c] [[d e] [f g]]] to [[a b c] [d e] [f g]]

Dustin Paluch00:03:47

you’re missing a paren in the first one


sorry, I fixed

Dustin Paluch01:03:38

(def foo '[[a b c] [[d e] [f g]]])
(apply vector (first foo) (second foo))


if I have more than only 2 elements?


(def foo '[[a b c] [[d e] [f g]] [[i j] [k l]]])


(reduce #(if (coll? (first %2)) (apply conj %1 %2) (conj %1 %2)) [] foo)


or if you prefer slightly more readable:

(reduce (fn [xs x] (if (coll? (first x)) (apply conj xs x) (conj xs x))) [] foo)

👍 1

It worked very well


thank you

👍 1
oxalorg (Mitesh)20:03:39

(def foo '[[a b c] [[d e] [f g]] [[i j] [k l]]])

(into [(first foo)]
      (mapcat identity (rest foo)))
;; => [[a b c] [d e] [f g] [i j] [k l]]
Maybe this works too?


@U031CHTGX1T Thank you for the response


But where to add this in above function?

Ferdinand Beyer11:03:30

You don’t, this is not meant to be defined per call, it’s a global setting


hmmm.. is it like add it in configuration file ?

Ferdinand Beyer11:03:12

Consider using async/pipeline to use dedicated threads and where you can specify the parallelism

Ferdinand Beyer11:03:48

You can specify that when starting the JVM (`-D` flag I believe)


probably on project.clj ?

Ferdinand Beyer11:03:29

:jvm-opts ["-Dclojure.core…=X"]

Ferdinand Beyer11:03:59

But it depends where you deploy your app as well

Ferdinand Beyer11:03:19

E.g. I think you will not run it in Leiningen in prod right


i have to use in prod


Can we change the value of clojure.core.async.pool-size at runtime? I mean I do not want to set it in project.clj or as in system property


I believe the answer to this is no. It's a jvm system property. But, also, it wouldn't be a good idea, because it could lead to unpredictable behavior. My recommendation is to go ahead and set the pool-size to a higher value (if that's really what you want to do), as pool size is something giving threads at disposal. But you should likely make sure that setting the pool size to a higher value is really what you want to do - if it will actually solve your problem. I would do a lot of experimentation first.


thanks for the response @U0G3Y3NA0, Is there any other property where we can increase or decrease threads in runtime?


what is the problem you are trying to solve?

upvote 1

this var is private probably for a good reason. As you can see in the docstring there are some problems you may encounter trying to change the value


by default it will be 8 right? So what we can do if we want some higher number of threads when we running below code

(->> data
       (fn []  (.....transformation logic..))
       (async/reduce conj [])

Ferdinand Beyer15:03:32

@U01J3DB39R6 — I think async/pipeline is what you really want. The async “dispatch” thread pool is for go blocks only, e.g. small non-blocking things. Unless you have a machine with A LOT of cores, changing this will probably not give you much. pipeline and friends allow you to use dedicated threads where you can easily tune the number of parallel tasks to run.

upvote 2
Ferdinand Beyer15:03:28

Since you are asking for the number of threads, it seems you want to do computation expensive or even blocking operations, in this case you should not use the dispatch pool anyway


Thanks for your response @U031CHTGX1T, But I did not get what you meant by dispatch here

delaguardo16:03:56 here is a good article explaining what is thread-pool in core async and how it is connected with blocking go blocks

👀 1
Ferdinand Beyer16:03:08

Probably explained in the article @U04V4KLKC shared. “dispatch thread pool” is just the name of the fixed-size thread pool that can be adjusted with the pool size property


I would recommend if you want too customize an executor of sorts

Ferdinand Beyer18:03:25

Sorry, I don’t understand your question. Thoughts on what?

Noah Bogart18:03:01

Not sure where to ask this, but is there any news about ? It hasn't had any code changes since last August, there are a bunch of issues and pull requests that haven't been touched in that time, and it hasn’t updated to include any changes to core libraries (core.async for example), let alone clojure 1.11 updates.

oxalorg (Mitesh)20:03:15

I was wondering the same thing! 😿

Noah Bogart20:03:25

@U4J1HQKFH hey there, any news?


I mean, Clojure 1.11 was just released days ago. Give them a bit of time 🙂. OK to ask, of course.

🙌 1
👍 1
Noah Bogart01:03:32

Hah that's true, but it seemed prudent to ask given that no other work has been done on the site since last year either.


is there a way to enable me to say ::foo/key without loading the foo namespace, I just want the key ns sugars. And maybe I can't load foo right now

Alex Miller (Clojure team)18:03:30

in Clojure 1.11 you can now use (:require [ :as-alias foo])

👍 1
Alex Miller (Clojure team)18:03:08

pre-1.11 you could do

(create-ns '
(alias 'foo '

👍 1
Alex Miller (Clojure team)18:03:46

(and yes, it's ok to later load if you need to)

👍 1

I’d also question if you need auto resolve keyword namespaces at all. Sometimes the answer is yes, but often the answer is :foo/key is just as valid


I thought :foo/key would be correct in this case? ::foo/key is necessary when you alias/shorten a namespace into foo

Sam Ritchie23:03:39

I have found it is a nice catch for typos (at least in the namespace piece); also, for these java-ish long namespaces like :sicmutils.expression.simplifier/option

Prithvi Hv20:03:13

i been using calva as my repl development tool. I'm able to load and execute imports and funcs i have written, but unable to load the whole namespace or file. Can someone point out what im doing wrong?

Prithvi Hv20:03:17

groww-scraper.core=> (load-file "src/groww_scraper/core.clj")
((require (quote [clj-http.client :as client]) (quote [cheshire.core :as json]) (quote [environ.core :refer [env]]) (quote [clj-time.core :as t]) (quote [clj-time.coerce :as tc]) (quote [next.jdbc :as jdbc]) (quote [next.jdbc.types :as jdbc.types]) (quote [ :as]) (quote [honey.sql :as sql]) (quote [honey.sql.helpers :as sqlh])) (:gen-class)) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form


There's something wrong with the ns form in that file. Looks like you might be using require instead of :require? Also, I don't use Calva so I'm not sure, but I think you might want to use the "Load current file" command instead of load-file:

🙏 1

It is certainly more convenient to use the Calva command for it. Then you can stay in the file. Have you found the Getting Started REPL, @U037THMHCD8? There's a command that starts it. It will open up some files for you which form a guide where you can learn Calva, some structural editing and even some Clojure. (And I now realize I should spend some more time on introducing the ns form in that guide.)


The ns form is indeed a bit of a beast. is a pretty good cheat sheet.


Hovering the ns form shows the docs for it, as well as ClojureDocs examples.

👍 1

Wonder if clj-kondo could/should flag require vs :require in the ns form…?


It probably should!

Prithvi Hv04:03:31

@U0ETXRFEW im able to reproduce this in the repl by calling the load function

Prithvi Hv04:03:42

this is what my import looks like:

(ns groww-scraper.core
  (require '[clj-http.client :as client]
           '[cheshire.core :as json]
           '[environ.core :refer [env]]
           '[clj-time.core :as t]
           '[clj-time.coerce :as tc]
           '[next.jdbc :as jdbc]
           '[next.jdbc.types :as jdbc.types]
           '[ :as]
           '[honey.sql :as sql]
           '[honey.sql.helpers :as sqlh])

Prithvi Hv04:03:30

when i switch from require to :require and remove the ' it worked 🎉 @U4ZDX466T @U0ETXRFEW the NS form cheatsheet link and docs/comments on calva were very helpful. to sum it up: with the ns form i was never suppose to use the require function. It was should be a dataobject, right?


Correct. The ns macro handles the quoting and the calling. Glad you solved it!

Jon Olick20:03:58

man there are like soooo many random functions in the core libs

Sam Ritchie23:03:29

nah, just 4 😉


4 out of about 600 things that can be called as functions in Cloure.core seems quite a small number

Sam Ritchie07:03:19

@U05254DQM I think @U036UA9LZSQ was saying that the standard library is much larger than one might expect, using “random” as in “why is this here?” I was attempting a joke by taking “random” very literally!

Jon Olick20:03:11

definitely more CISC than RISC


If it helps to see a large fraction of them broken down into categories of related functionality, check out the cheatsheet: or here

👀 1

hi, i'm building a prototype REST API for accessing and adding a collection of songs using Compojure and Datomic. i made d/db an atom and when I POST to add a song, i also update the db atom by using swap!. however, i am running into errors doing this. my question is, how is keeping the datomic cached db up to date usually done in a web application?


I’m not entirely sure I understand, but I assume you are swapping the db value with some other thing related to a POST request? However I don’t think doing that (and maybe even holding the db in an atom) is really necessary or what you actually want? You might just want to use d/transact on the db value with your new data.


If you want to cache reads on top of that, you might want to run any queries first and then cache the actual view you want to present in your app. Or you can do something very simple with E-Tag or Last-Modified so the browser takes care of caching responses. Datomic should be able to help you there.